From 95e98319ebfae8ca24146e4817d5ee5c8f289150 Mon Sep 17 00:00:00 2001 From: laishenghao Date: Thu, 27 Mar 2025 16:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3DEBUG=E7=89=88=E5=88=86?= =?UTF-8?q?=E5=8C=BA=E8=A1=A8=E5=9C=A8=E7=A6=81=E7=94=A8seqscan=E6=97=B6co?= =?UTF-8?q?unt=E5=87=BA=E7=8E=B0core=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 | 5 ++ src/test/regress/expected/gpi_index_only.out | 61 +++++++++++++++++++ src/test/regress/sql/gpi_index_only.sql | 31 ++++++++++ 3 files changed, 97 insertions(+) diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index d4b079f077..ba6a1dc229 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -677,6 +677,11 @@ static Plan* create_scan_plan(PlannerInfo* root, Path* best_path) tlist = build_path_tlist(root, best_path); } + if (u_sess->opt_cxt.is_under_append_plan && tlist == NIL) { + Const *c = makeConst(INT4OID, -1, InvalidOid, -2, (Datum)0, true, false); + tlist = lappend(tlist, makeTargetEntry((Expr*)c, 1, NULL, true)); + } + /* * Extract the relevant restriction clauses from the parent relation. The * executor must apply all these restrictions during the scan, except for diff --git a/src/test/regress/expected/gpi_index_only.out b/src/test/regress/expected/gpi_index_only.out index 1c4416d1bc..cd4cb24b11 100644 --- a/src/test/regress/expected/gpi_index_only.out +++ b/src/test/regress/expected/gpi_index_only.out @@ -655,3 +655,64 @@ SELECT distinct(j),k drop table if exists gpi_J1_TBL; drop table if exists gpi_J2_TBL; set client_min_messages=notice; +-- test gpi index_scan_only with none targetlist +drop table if exists indexscan_pseudo_tlist cascade; +NOTICE: table "indexscan_pseudo_tlist" does not exist, skipping +CREATE TABLE indexscan_pseudo_tlist ( + id integer, + k integer, + t integer +) +partition by range (id) +( + partition indexscan_pseudo_tlist_p0 values less than (10000), + partition indexscan_pseudo_tlist_p1 values less than (20000), + partition indexscan_pseudo_tlist_p2 values less than (30000), + partition indexscan_pseudo_tlist_p3 values less than (maxvalue) +); +create index on indexscan_pseudo_tlist(id); +insert into indexscan_pseudo_tlist values(1); +reset enable_seqscan; +select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null; + count +------- + 2 +(1 row) + +set enable_seqscan=off; +explain(costs off) select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------- + Aggregate + -> Result + One-Time Filter: (now() IS NOT NULL) + -> Append + -> Result + One-Time Filter: (now() IS NOT NULL) + -> Index Only Scan using indexscan_pseudo_tlist_id_tableoid_idx on indexscan_pseudo_tlist + -> Result + One-Time Filter: (now() IS NOT NULL) + -> Index Only Scan using indexscan_pseudo_tlist_id_tableoid_idx on indexscan_pseudo_tlist +(10 rows) + +select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null; + count +------- + 2 +(1 row) + +select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null and id is not null; + count +------- + 2 +(1 row) + +prepare test_index_pseudo as select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where id in (1) and id=$1; +execute test_index_pseudo(1); + count +------- + 2 +(1 row) + +reset enable_seqscan; +drop table if exists indexscan_pseudo_tlist cascade; diff --git a/src/test/regress/sql/gpi_index_only.sql b/src/test/regress/sql/gpi_index_only.sql index 83e5be1329..4af048a1dd 100644 --- a/src/test/regress/sql/gpi_index_only.sql +++ b/src/test/regress/sql/gpi_index_only.sql @@ -237,3 +237,34 @@ SELECT distinct(j),k drop table if exists gpi_J1_TBL; drop table if exists gpi_J2_TBL; set client_min_messages=notice; + +-- test gpi index_scan_only with none targetlist +drop table if exists indexscan_pseudo_tlist cascade; +CREATE TABLE indexscan_pseudo_tlist ( + id integer, + k integer, + t integer +) +partition by range (id) +( + partition indexscan_pseudo_tlist_p0 values less than (10000), + partition indexscan_pseudo_tlist_p1 values less than (20000), + partition indexscan_pseudo_tlist_p2 values less than (30000), + partition indexscan_pseudo_tlist_p3 values less than (maxvalue) +); +create index on indexscan_pseudo_tlist(id); +insert into indexscan_pseudo_tlist values(1); + +reset enable_seqscan; +select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null; + +set enable_seqscan=off; +explain(costs off) select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null; +select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null; +select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where now() is not null and id is not null; + +prepare test_index_pseudo as select count(*) from (select * from indexscan_pseudo_tlist union all select * from indexscan_pseudo_tlist) where id in (1) and id=$1; +execute test_index_pseudo(1); + +reset enable_seqscan; +drop table if exists indexscan_pseudo_tlist cascade; -- Gitee