From 7a7360c4a5bc307cc524cf308872d19f62c2d20f Mon Sep 17 00:00:00 2001 From: Vinoth Veeraraghavan Date: Wed, 9 Feb 2022 16:46:46 +0800 Subject: [PATCH] Disqualify full scan as not jittable query in MOT JIT --- .../storage/mot/jit_exec/jit_plan.cpp | 9 ++++- .../storage/mot/jit_exec/jit_plan_expr.cpp | 33 ++++++++++++------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/gausskernel/storage/mot/jit_exec/jit_plan.cpp b/src/gausskernel/storage/mot/jit_exec/jit_plan.cpp index f16f388eb..594c37ec1 100644 --- a/src/gausskernel/storage/mot/jit_exec/jit_plan.cpp +++ b/src/gausskernel/storage/mot/jit_exec/jit_plan.cpp @@ -49,7 +49,12 @@ static bool countWhereClauseEqualsLeaves(Query* query, MOT::Table* table, MOT::I table->GetTableName().c_str(), index->GetName().c_str()); for (int i = 0; i < index->GetNumFields(); ++i) { - MOT_LOG_APPEND(MOT::LogLevel::LL_TRACE, "%s", table->GetFieldName(index->GetColumnKeyFields()[i])); + int columnId = index->GetColumnKeyFields()[i]; + if (columnId >= 0) { + MOT_LOG_APPEND(MOT::LogLevel::LL_TRACE, "%s", table->GetFieldName(columnId)); + } else { + MOT_LOG_APPEND(MOT::LogLevel::LL_TRACE, "N/A [column %d]", columnId); + } if ((i + 1) < index->GetNumFields()) { MOT_LOG_APPEND(MOT::LogLevel::LL_TRACE, ", "); } @@ -318,6 +323,8 @@ static bool allocFilterArray(JitFilterArray* filter_array, int filter_count) (unsigned)alloc_size, filter_count); } else { + errno_t erc = memset_s(filter_array->_scan_filters, alloc_size, 0, alloc_size); + securec_check(erc, "\0", "\0"); filter_array->_filter_count = filter_count; result = true; } diff --git a/src/gausskernel/storage/mot/jit_exec/jit_plan_expr.cpp b/src/gausskernel/storage/mot/jit_exec/jit_plan_expr.cpp index 6fdf59424..038307f72 100644 --- a/src/gausskernel/storage/mot/jit_exec/jit_plan_expr.cpp +++ b/src/gausskernel/storage/mot/jit_exec/jit_plan_expr.cpp @@ -147,10 +147,14 @@ void RangeScanExpressionCollector::EvaluateScanType() // if no expression was collected, this is an invalid scan (we do not support full scans yet) int columnCount = _index_op_count; if (_index_op_count == 0) { +#ifdef MOT_JIT_FULL_SCAN MOT_LOG_TRACE("RangeScanExpressionCollector(): no expression was collected, assuming full scan"); _index_scan->_scan_type = JIT_INDEX_SCAN_FULL; _index_scan->_column_count = 0; _index_scan->_search_exprs._count = 0; +#else + MOT_LOG_TRACE("RangeScanExpressionCollector(): Disqualifying query - full scan"); +#endif return; } @@ -917,20 +921,22 @@ static void freeFuncExpr(JitFuncExpr* func_expr) void freeExpr(JitExpr* expr) { - switch (expr->_expr_type) { - case JIT_EXPR_TYPE_OP: - freeOpExpr((JitOpExpr*)expr); - break; + if (expr != nullptr) { + switch (expr->_expr_type) { + case JIT_EXPR_TYPE_OP: + freeOpExpr((JitOpExpr*)expr); + break; - case JIT_EXPR_TYPE_FUNC: - freeFuncExpr((JitFuncExpr*)expr); - break; + case JIT_EXPR_TYPE_FUNC: + freeFuncExpr((JitFuncExpr*)expr); + break; - default: - break; + default: + break; + } + + MOT::MemSessionFree(expr); } - - MOT::MemSessionFree(expr); } static bool containsExpr(const JitColumnExprArray* pkey_exprs, const Expr* expr) @@ -1409,9 +1415,14 @@ bool getRangeSearchExpressions( } else { Node* quals = query->jointree->quals; if (quals == nullptr) { +#ifdef MOT_JIT_FULL_SCAN MOT_LOG_TRACE("No range search expressions collected (empty WHERE clause) - using a full index scan"); index_scan->_scan_type = JIT_INDEX_SCAN_FULL; return true; +#else + MOT_LOG_TRACE("Query is not jittable: requires full scan"); + return false; +#endif } if (!visitSearchExpressions( query, table, index, (Expr*)&quals[0], true, &expr_collector, join_clause_type == JoinClauseImplicit)) {