From 07607df51656d4e2151f4bf36b2a5ec3161b9a4a Mon Sep 17 00:00:00 2001 From: lilongfei Date: Wed, 11 Oct 2023 11:14:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Din=E4=B8=AD=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=97=B6=E6=80=A7=E8=83=BD=E6=B3=A2=E5=8A=A8?= =?UTF-8?q?=E8=BE=83=E5=A4=A7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/optimizer/plan/createplan.cpp | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index b598f88b6..44a85487f 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -49,6 +49,7 @@ #include "optimizer/planmain.h" #include "optimizer/planner.h" #include "optimizer/predtest.h" +#include "optimizer/prep.h" #include "optimizer/restrictinfo.h" #include "optimizer/subselect.h" #include "optimizer/tlist.h" @@ -2667,6 +2668,28 @@ static Scan* create_indexscan_plan( return scan_plan; } +static bool CheckBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node *clause) +{ + foreach_cell (cell, indexquals) { + Node *node = lfirst_node(Node, cell); + if (equal((const void *)node, (const void *)clause)) { + return true; + } + + if (IsA(node, BoolExpr)) { + BoolExpr *be = (BoolExpr *)node; + if (be->boolop != AND_EXPR) { + continue; + } + if (CheckBitmapScanQualExists(root, be->args, clause)) { + return true; + } + } + } + + return false; +} + /* * create_bitmap_scan_plan * Returns a bitmap scan plan for the base relation scanned by 'best_path' @@ -2717,6 +2740,9 @@ static BitmapHeapScan* create_bitmap_scan_plan( * the scan becomes lossy, so they have to be included in bitmapqualorig. */ qpqual = NIL; + if (indexquals != NIL && IsA(best_path->bitmapqual, BitmapOrPath)) { + linitial(indexquals) = canonicalize_qual(linitial_node(Expr, indexquals), false); + } foreach (l, scan_clauses) { RestrictInfo* rinfo = (RestrictInfo*)lfirst(l); Node* clause = (Node*)rinfo->clause; @@ -2724,7 +2750,7 @@ static BitmapHeapScan* create_bitmap_scan_plan( Assert(IsA(rinfo, RestrictInfo)); if (rinfo->pseudoconstant) continue; /* we may drop pseudoconstants here */ - if (list_member(indexquals, clause)) + if (CheckBitmapScanQualExists(root, indexquals, clause)) continue; /* simple duplicate */ if (rinfo->parent_ec && list_member_ptr(indexECs, rinfo->parent_ec)) continue; /* derived from same EquivalenceClass */