From 07607df51656d4e2151f4bf36b2a5ec3161b9a4a Mon Sep 17 00:00:00 2001 From: lilongfei Date: Wed, 11 Oct 2023 11:14:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Din=E4=B8=AD=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8D=E5=90=8C=E6=97=B6=E6=80=A7=E8=83=BD=E6=B3=A2?= =?UTF-8?q?=E5=8A=A8=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 */ From b57e24891519b4fbca17986497987f2470c5e449 Mon Sep 17 00:00:00 2001 From: lilongfei Date: Tue, 17 Oct 2023 10:57:50 +0800 Subject: [PATCH 2/3] change function name in createplan.cpp --- src/gausskernel/optimizer/plan/createplan.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index 44a85487f..6f46ef5fd 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -2668,7 +2668,7 @@ static Scan* create_indexscan_plan( return scan_plan; } -static bool CheckBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node *clause) +static bool checkBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node *clause) { foreach_cell (cell, indexquals) { Node *node = lfirst_node(Node, cell); @@ -2681,7 +2681,7 @@ static bool CheckBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node if (be->boolop != AND_EXPR) { continue; } - if (CheckBitmapScanQualExists(root, be->args, clause)) { + if (checkBitmapScanQualExists(root, be->args, clause)) { return true; } } @@ -2750,7 +2750,7 @@ static BitmapHeapScan* create_bitmap_scan_plan( Assert(IsA(rinfo, RestrictInfo)); if (rinfo->pseudoconstant) continue; /* we may drop pseudoconstants here */ - if (CheckBitmapScanQualExists(root, 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 */ From 2169da72da7e8bd382ae85f508279481d5496cd4 Mon Sep 17 00:00:00 2001 From: lilongfei Date: Thu, 2 Nov 2023 07:36:37 +0000 Subject: [PATCH 3/3] =?UTF-8?q?update=20src/gausskernel/optimizer/plan/cre?= =?UTF-8?q?ateplan.cpp.=20=E6=9B=B4=E6=94=B9checkBitmapScanQualExists?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=91=BD=E5=90=8D=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lilongfei --- src/gausskernel/optimizer/plan/createplan.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index 6f46ef5fd..44a85487f 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -2668,7 +2668,7 @@ static Scan* create_indexscan_plan( return scan_plan; } -static bool checkBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node *clause) +static bool CheckBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node *clause) { foreach_cell (cell, indexquals) { Node *node = lfirst_node(Node, cell); @@ -2681,7 +2681,7 @@ static bool checkBitmapScanQualExists(PlannerInfo *root, List *indexquals, Node if (be->boolop != AND_EXPR) { continue; } - if (checkBitmapScanQualExists(root, be->args, clause)) { + if (CheckBitmapScanQualExists(root, be->args, clause)) { return true; } } @@ -2750,7 +2750,7 @@ static BitmapHeapScan* create_bitmap_scan_plan( Assert(IsA(rinfo, RestrictInfo)); if (rinfo->pseudoconstant) continue; /* we may drop pseudoconstants here */ - if (checkBitmapScanQualExists(root, 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 */