diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index d4b079f07781799efe284c9b67aef5945c285595..ba6a1dc229b85d855ecfecb9865b6bc1c0b7d274 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 1c4416d1bcb8dfeee70d9dcb820014594b3625e0..cd4cb24b112b6928349621afa8cbec713407307f 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 83e5be13294353cef4a66f485399e73e991547e6..4af048a1ddb288b3f3cb901494783a6139186202 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;