!1425 index代价高估导致走bitmapscan

Merge pull request !1425 from Cross-罗/index_cost
This commit is contained in:
opengauss-bot 2021-12-24 01:47:37 +00:00 committed by Gitee
commit f14f8188c4
14 changed files with 1009 additions and 1015 deletions

View File

@ -6518,7 +6518,8 @@ static void genericcostestimate(PlannerInfo* root, IndexPath* path, double loop_
* enough to not alter index-vs-seqscan decisions, but will prevent
* indexes of different sizes from looking exactly equally attractive.
*/
*indexTotalCost += index->pages * spc_random_page_cost / 100000.0;
if (ENABLE_SQL_BETA_FEATURE(INDEX_COST_WITH_LEAF_PAGES_ONLY))
*indexTotalCost += index->pages * spc_random_page_cost / 100000.0;
/*
* CPU cost: any complex expressions in the indexquals will need to be

View File

@ -995,6 +995,8 @@ static const struct config_enum_entry sql_beta_options[] = {
{"param_path_opt", PARAM_PATH_OPT, false},
{"no_unique_index_first", NO_UNIQUE_INDEX_FIRST, false},
{"join_sel_with_cast_func", JOIN_SEL_WITH_CAST_FUNC, false},
{"canonical_pathkey", CANONICAL_PATHKEY, false},
{"index_cost_with_leaf_pages_only", INDEX_COST_WITH_LEAF_PAGES_ONLY, false},
{NULL, 0, false}
};

View File

@ -358,7 +358,9 @@ typedef enum {
PARAM_PATH_OPT = 16, /* Parametrized Path Optimization. */
PAGE_EST_OPT = 32, /* More accurate (rowstored) index pages estimation */
NO_UNIQUE_INDEX_FIRST = 64, /* use unique index first rule in path generation */
JOIN_SEL_WITH_CAST_FUNC = 128 /* support cast function while calculating join selectivity */
JOIN_SEL_WITH_CAST_FUNC = 128, /* support cast function while calculating join selectivity */
CANONICAL_PATHKEY = 256, /* Use canonicalize pathkeys directly */
INDEX_COST_WITH_LEAF_PAGES_ONLY = 512 /* compute index cost with consideration of leaf-pages-only */
} sql_beta_param;
#define ENABLE_PRED_PUSH(root) \

View File

@ -7,6 +7,7 @@ set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
drop table if exists test_bypass_sq1;
NOTICE: table "test_bypass_sq1" does not exist, skipping
create table test_bypass_sq1(col1 int, col2 int, col3 text);

View File

@ -7,6 +7,7 @@ set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
-- create table
drop table if exists test_bypass_sq1;
NOTICE: table "test_bypass_sq1" does not exist, skipping

View File

@ -227,11 +227,11 @@ Number of partition: 5 (View pg_partition to check each partition range.)
insert into test_gpi_create_like values(generate_series(0,9999), 1);
explain (costs off) select * from test_gpi_create_like where c1 = 0;
QUERY PLAN
-----------------------------------------------------------------
QUERY PLAN
--------------------------------------------------------------------
Bitmap Heap Scan on test_gpi_create_like
Recheck Cond: (c1 = 0)
-> Bitmap Index Scan on test_gpi_create_like_c1_tableoid_idx
-> Bitmap Index Scan on test_gpi_create_like_c1_c2_tableoid_idx
Index Cond: (c1 = 0)
(4 rows)

View File

@ -21,9 +21,9 @@ select a.relname,a.parttype,a.reloptions from pg_partition a, pg_class b where a
(2 rows)
explain (costs off) select * from test_gpi_more_invalid where a >= 3000;
QUERY PLAN
---------------------------------------------------------------------------
Index Scan using global_index_gpi_more_invalid_b on test_gpi_more_invalid
QUERY PLAN
------------------------------------------------------------------------------------
Index Only Scan using global_index_gpi_more_invalid_a_b_c on test_gpi_more_invalid
Index Cond: (a >= 3000)
(2 rows)
@ -55,10 +55,10 @@ explain (costs off) select count(*) from test_gpi_more_invalid where a <= 100 an
(4 rows)
explain (costs off) select count(*) from test_gpi_more_invalid where a > 3000;
QUERY PLAN
--------------------------------------------------------------------------------------
QUERY PLAN
------------------------------------------------------------------------------------------
Aggregate
-> Index Only Scan using global_index_gpi_more_invalid_b on test_gpi_more_invalid
-> Index Only Scan using global_index_gpi_more_invalid_a_b_c on test_gpi_more_invalid
Index Cond: (a > 3000)
(3 rows)

View File

@ -119,12 +119,11 @@ select * from gpi_index_test where a < 200 and b > 190 order by a;
-- multi column index with global index
create index gpi_index_test_global_a_b on gpi_index_test(a,b) global;
explain (costs off) select * from gpi_index_test where a = 200 and b = 100;
QUERY PLAN
------------------------------------------------------------
Index Scan using gpi_index_test_global_b on gpi_index_test
Index Cond: (b = 100)
Filter: (a = 200)
(3 rows)
QUERY PLAN
--------------------------------------------------------------
Index Scan using gpi_index_test_global_a_b on gpi_index_test
Index Cond: ((a = 200) AND (b = 100))
(2 rows)
select * from gpi_index_test where a = 100 and b = 100 order by a;
a | b | c

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,34 @@
set enable_opfusion=on;
set enable_partition_opfusion=on;
set enable_bitmapscan=off;
set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
--create table
drop table if exists test_bypass_sql_partition;
set enable_opfusion=on;
set enable_partition_opfusion=on;
set enable_bitmapscan=off;
set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
--create table
drop table if exists test_bypass_sql_partition;
NOTICE: table "test_bypass_sql_partition" does not exist, skipping
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
explain execute p11(0,0,'test_insert');
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
explain execute p11(0,0,'test_insert');
QUERY PLAN
-----------------------------------------------------------------------
[Bypass]
@ -35,13 +36,13 @@ explain execute p11(0,0,'test_insert');
-> Result (cost=0.00..0.01 rows=1 width=0)
(3 rows)
execute p11(10,10,'test_insert');
execute p11(12,12,'test_insert');
execute p11(-1,-1,'test_insert2');
execute p11(23,23,'test_insert2');
execute p11(33,33,'test_insert3');
execute p11(0,0,'test_insert3');
explain execute p12(1,1);
execute p11(10,10,'test_insert');
execute p11(12,12,'test_insert');
execute p11(-1,-1,'test_insert2');
execute p11(23,23,'test_insert2');
execute p11(33,33,'test_insert3');
execute p11(0,0,'test_insert3');
explain execute p12(1,1);
QUERY PLAN
-----------------------------------------------------------------------
[Bypass]
@ -49,18 +50,18 @@ explain execute p12(1,1);
-> Result (cost=0.00..0.01 rows=1 width=0)
(3 rows)
execute p12(1,1);
execute p12(22,22);
execute p12(20,20);
--nobypass
execute p11(null,null,null);
execute p12(1,1);
execute p12(22,22);
execute p12(20,20);
--nobypass
execute p11(null,null,null);
ERROR: inserted partition key does not map to any table partition
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
execute p_insert1;
--bypass
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
explain execute p13(0,0);
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
execute p_insert1;
--bypass
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
explain execute p13(0,0);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -71,39 +72,39 @@ explain execute p13(0,0);
Selected Partitions: PART
(6 rows)
execute p13(0,0);
execute p13(0,0);
col1 | col2 | col3
------+------+--------------
0 | 0 | test_insert3
0 | 0 | aaaaaaa
(2 rows)
execute p13(10,0);
execute p13(10,0);
col1 | col2 | col3
------+------+---------
10 | 0 | aaaaaaa
(1 row)
execute p13(20,0);
execute p13(20,0);
col1 | col2 | col3
------+------+---------
20 | 0 | aaaaaaa
(1 row)
execute p13(30,0);
execute p13(30,0);
col1 | col2 | col3
------+------+---------
30 | 0 | aaaaaaa
(1 row)
execute p13(40,0);
execute p13(40,0);
col1 | col2 | col3
------+------+---------
40 | 0 | aaaaaaa
(1 row)
set enable_indexonlyscan=off;
explain execute p13(0,0);
set enable_indexonlyscan=off;
explain execute p13(0,0);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -114,16 +115,16 @@ explain execute p13(0,0);
Selected Partitions: PART
(6 rows)
execute p13(0,0);
execute p13(0,0);
col1 | col2 | col3
------+------+--------------
0 | 0 | test_insert3
0 | 0 | aaaaaaa
(2 rows)
reset enable_indexonlyscan;
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
explain execute p15 (0,0,'test_update',-1);
reset enable_indexonlyscan;
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
explain execute p15 (0,0,'test_update',-1);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -135,9 +136,9 @@ explain execute p15 (0,0,'test_update',-1);
Selected Partitions: PART
(7 rows)
execute p15 (0,0,'test_update',-1);
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
explain execute p16(5,3,1,1);
execute p15 (0,0,'test_update',-1);
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
explain execute p16(5,3,1,1);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -149,13 +150,13 @@ explain execute p16(5,3,1,1);
Selected Partitions: PART
(7 rows)
execute p16(5,3,1,1);
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
execute p101 (111,'test_update2',-1);
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
execute p102 (1);
execute p16(5,3,1,1);
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
execute p101 (111,'test_update2',-1);
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
execute p102 (1);
col1 | col2 | col3
------+------+---------
1 | 0 | aaaaaaa
@ -172,14 +173,14 @@ execute p102 (1);
1 | 100 | aaaaaaa
(12 rows)
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
explain execute p1011;
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
explain execute p1011;
QUERY PLAN
-----------------------------------------------------------------------
[Bypass]
@ -187,8 +188,8 @@ explain execute p1011;
-> Result (cost=0.00..0.01 rows=1 width=0)
(3 rows)
execute p1011;
explain execute p1012;
execute p1011;
explain execute p1012;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -199,13 +200,13 @@ explain execute p1012;
Selected Partitions: 1
(6 rows)
execute p1012;
execute p1012;
col1 | col2 | col3
------+------+----------
-3 | -3 | test_pbe
(1 row)
explain execute p1013;
explain execute p1013;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -217,8 +218,8 @@ explain execute p1013;
Selected Partitions: 1
(7 rows)
execute p1013;
explain execute p1014;
execute p1013;
explain execute p1014;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -230,14 +231,14 @@ explain execute p1014;
Selected Partitions: 1
(7 rows)
execute p1014;
execute p1014;
col1 | col2 | col3
------+------+----------
-3 | 10 | test_pbe
(1 row)
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
explain execute p10141;
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
explain execute p10141;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -249,15 +250,15 @@ explain execute p10141;
Selected Partitions: 1
(7 rows)
execute p10141;
execute p10141;
col1 | col2
------+------
-3 | 10
(1 row)
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p1021(1);
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p1021(1);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -269,16 +270,16 @@ explain execute p1021(1);
Selected Partitions: PART
(7 rows)
execute p1021(1);
execute p1021(1);
col1 | col2 | col3
------+------+---------
1 | 0 | aaaaaaa
(1 row)
--bypass through index only scan
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p10211(1);
--bypass through index only scan
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p10211(1);
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -290,14 +291,14 @@ explain execute p10211(1);
Selected Partitions: PART
(7 rows)
execute p10211(1);
execute p10211(1);
col1 | col2
------+------
1 | 0
(1 row)
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
explain execute p10212(1);
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
explain execute p10212(1);
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -309,7 +310,7 @@ explain execute p10212(1);
Selected Partitions: PART
(7 rows)
execute p10212(1);
execute p10212(1);
col1 | col2
------+------
1 | 2
@ -325,8 +326,8 @@ execute p10212(1);
1 | 100
(11 rows)
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
explain execute p10213(1);
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
explain execute p10213(1);
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -338,14 +339,14 @@ explain execute p10213(1);
Selected Partitions: PART
(7 rows)
execute p10213(1);
execute p10213(1);
col1 | col2
------+------
1 | 0
(1 row)
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
explain execute p10214(1);
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
explain execute p10214(1);
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -357,7 +358,7 @@ explain execute p10214(1);
Selected Partitions: PART
(7 rows)
execute p10214(1);
execute p10214(1);
col1 | col2
------+------
1 | 0
@ -374,25 +375,25 @@ execute p10214(1);
1 | 100
(12 rows)
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
execute p1024;
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
execute p1024;
col1 | col2 | col3
------+------+-------------
0 | -1 | test_update
(1 row)
execute p1025(1);
execute p1025(1);
col1 | col2 | col3
------+------+---------
1 | 0 | aaaaaaa
(1 row)
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
execute p104 (3);
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
execute p104 (3);
col1 | col2 | col3
------+------+---------
3 | 0 | aaaaaaa
@ -408,16 +409,16 @@ execute p104 (3);
3 | 100 | aaaaaaa
(11 rows)
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
execute p1052(2);
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
execute p1052(2);
col1 | col2
------+------
2 | 0
2 | 10
(2 rows)
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
execute p10601 (0,10,1);
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
execute p10601 (0,10,1);
col1 | col2
------+------
1 | 2
@ -513,17 +514,17 @@ execute p10601 (0,10,1);
9 | 100
(91 rows)
--nobypass
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
execute p1020;
--nobypass
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
execute p1020;
col1 | col2 | col3
------+------+---------
1 | 0 | aaaaaaa
(1 row)
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
explain execute p10200;
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
explain execute p10200;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not support query in multiple partitions.
@ -535,14 +536,14 @@ explain execute p10200;
Selected Partitions: 1..8
(7 rows)
execute p10200;
execute p10200;
col1 | col2
------+------
1 | 0
(1 row)
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
explain execute p1022(0,3);
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
explain execute p1022(0,3);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
@ -554,7 +555,7 @@ explain execute p1022(0,3);
Selected Partitions: PART
(7 rows)
execute p1022(0,3);
execute p1022(0,3);
col1 | col2 | col3
------+------+-------------
0 | -1 | test_update
@ -562,7 +563,7 @@ execute p1022(0,3);
0 | 1 | test
(3 rows)
explain execute p1022(0,null);
explain execute p1022(0,null);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
@ -574,7 +575,7 @@ explain execute p1022(0,null);
Selected Partitions: PART
(7 rows)
execute p1022(0,null);
execute p1022(0,null);
col1 | col2 | col3
------+------+-------------
0 | -1 | test_update
@ -691,8 +692,8 @@ execute p1022(0,null);
0 | 100 | aaaaaaa
(112 rows)
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
explain execute p1023(0,3,2);
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
explain execute p1023(0,3,2);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
@ -704,7 +705,7 @@ explain execute p1023(0,3,2);
Selected Partitions: PART
(7 rows)
execute p1023(0,3,2);
execute p1023(0,3,2);
col1 | col2 | col3
------+------+------
0 | 1 | test
@ -712,9 +713,9 @@ execute p1023(0,3,2);
0 | 3 | test
(3 rows)
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
explain execute p1026(0,3);
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
explain execute p1026(0,3);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
@ -727,7 +728,7 @@ explain execute p1026(0,3);
Selected Partitions: PART
(8 rows)
execute p1026(0,3);
execute p1026(0,3);
col1 | col2 | col3
------+------+-------------
0 | -1 | test_update
@ -735,7 +736,7 @@ execute p1026(0,3);
0 | 1 | test
(3 rows)
explain execute p1027(0,3,2);
explain execute p1027(0,3,2);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
@ -748,7 +749,7 @@ explain execute p1027(0,3,2);
Selected Partitions: PART
(8 rows)
execute p1027(0,3,2);
execute p1027(0,3,2);
col1 | col2 | col3
------+------+------
0 | 1 | test
@ -756,24 +757,24 @@ execute p1027(0,3,2);
0 | 3 | test
(3 rows)
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
execute p103 (2);
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
execute p103 (2);
col1 | col2
------+------
0 | 2
1 | 2
(2 rows)
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
execute p105 (5);
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
execute p105 (5);
col1 | col2
------+------
-3 | 10
-1 | 111
(2 rows)
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
execute p1051(5,3);
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
execute p1051(5,3);
col1 | col2
------+------
4 | 0
@ -781,8 +782,8 @@ execute p1051(5,3);
4 | 20
(3 rows)
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
execute p106 (0,1);
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
execute p106 (0,1);
col1 | col2
------+------
1 | 2
@ -790,16 +791,16 @@ execute p106 (0,1);
1 | 20
(3 rows)
--bypass
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
execute p17 (3,3);
--bypass
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
execute p17 (3,3);
col1 | col2 | col3
------+------+------
(0 rows)
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
explain execute p18(3,7,3,3);
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
explain execute p18(3,7,3,3);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -811,9 +812,9 @@ explain execute p18(3,7,3,3);
Selected Partitions: PART
(7 rows)
execute p18(3,7,3,3);
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
execute p111;
execute p18(3,7,3,3);
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
execute p111;
col1 | col2
------+------
19 | 100
@ -918,8 +919,8 @@ execute p111;
11 | 0
(100 rows)
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
execute p112;
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
execute p112;
col1 | col2
------+------
11 | 0
@ -934,9 +935,9 @@ execute p112;
11 | 90
(10 rows)
--nobypass
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
explain execute p181(111);
--nobypass
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
explain execute p181(111);
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because the partition key is not in the parameters.
@ -948,23 +949,23 @@ explain execute p181(111);
Selected Partitions: NONE
(7 rows)
execute p181(111);
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
execute p191;
execute p181(111);
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
execute p191;
col1 | col2 | col3
------+------+------
(0 rows)
execute p192;
--error
execute p11(null,null,'test_null');
execute p192;
--error
execute p11(null,null,'test_null');
ERROR: inserted partition key does not map to any table partition
--bypass through index only scan
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
explain execute p11301 (2);
--bypass through index only scan
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
explain execute p11301 (2);
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -975,7 +976,7 @@ explain execute p11301 (2);
Selected Partitions: PART
(6 rows)
execute p11301 (2);
execute p11301 (2);
col1 | col2
------+------
2 | 100
@ -991,8 +992,8 @@ execute p11301 (2);
2 | 0
(11 rows)
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
explain execute p11401 (2);
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
explain execute p11401 (2);
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -1003,7 +1004,7 @@ explain execute p11401 (2);
Selected Partitions: PART
(6 rows)
execute p11401 (2);
execute p11401 (2);
col1 | col2
------+------
2 | 0
@ -1019,8 +1020,8 @@ execute p11401 (2);
2 | 100
(11 rows)
set enable_indexonlyscan=off;
explain execute p11301 (2);
set enable_indexonlyscan=off;
explain execute p11301 (2);
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
[Bypass]
@ -1031,7 +1032,7 @@ explain execute p11301 (2);
Selected Partitions: PART
(6 rows)
execute p11401 (2);
execute p11401 (2);
col1 | col2
------+------
2 | 0
@ -1047,13 +1048,13 @@ execute p11401 (2);
2 | 100
(11 rows)
reset enable_indexonlyscan;
--nobypass
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
execute p120 (0, 9);
--not bypass
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
explain execute p115;
reset enable_indexonlyscan;
--nobypass
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
execute p120 (0, 9);
--not bypass
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
explain execute p115;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query's scan operator is not index.
@ -1065,7 +1066,7 @@ explain execute p115;
Selected Partitions: 1..8
(7 rows)
execute p115;
execute p115;
col1 | col2 | col3
------+------+--------------
-1 | 111 | test_update2
@ -2149,8 +2150,8 @@ execute p115;
0 | -1 | test_update
(1079 rows)
prepare p116 as select * from test_bypass_sql_partition order by col2;
explain execute p116;
prepare p116 as select * from test_bypass_sql_partition order by col2;
explain execute p116;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
[No Bypass]reason: Bypass not executed because query's scan operator is not index.
@ -2162,7 +2163,7 @@ explain execute p116;
Selected Partitions: 1..8
(7 rows)
execute p116;
execute p116;
col1 | col2 | col3
------+------+--------------
0 | -1 | test_update
@ -3246,10 +3247,10 @@ execute p116;
-1 | 111 | test_update2
(1079 rows)
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
execute p117;
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
execute p117;
col1 | col2
------+------
-3 | 10
@ -3264,7 +3265,7 @@ execute p117;
0 | 6
(10 rows)
execute p118;
execute p118;
col2 | col1
------+------
10 | -3
@ -3279,7 +3280,7 @@ execute p118;
6 | 0
(10 rows)
execute p119;
execute p119;
col1 | col2
------+------
79 | 100
@ -3294,11 +3295,11 @@ execute p119;
79 | 10
(10 rows)
--bypass
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
execute p_select1(0);
--bypass
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
execute p_select1(0);
col1 | col2 | col3
------+------+-------------
0 | -1 | test_update
@ -3313,8 +3314,8 @@ execute p_select1(0);
0 | 8 | test
(10 rows)
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
execute p_select2(0);
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
execute p_select2(0);
col1 | col2 | col3
------+------+-------------
0 | -1 | test_update
@ -3329,12 +3330,12 @@ execute p_select2(0);
0 | 8 | test
(10 rows)
--nobypass
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
execute p_select3;
--nobypass
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
execute p_select3;
col1 | col2
------+------
-3 | 10
@ -3349,9 +3350,9 @@ execute p_select3;
0 | 6
(10 rows)
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
execute p_select4(20,10);
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
execute p_select4(20,10);
col1 | col2
------+------
11 | 0
@ -3366,40 +3367,40 @@ execute p_select4(20,10);
11 | 90
(10 rows)
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
execute p_select5(11,15);
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
execute p_select5(11,15);
col1 | col2
------+------
(0 rows)
--bypass
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
execute p_update1(1, 10);
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
execute p_update2('test_null',1,1);
--nobypass
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
update test_bypass_sql_partition set col3='test_null' where true;
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
execute p_update3(1,1,10);
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
execute p_update4('test_null',11,15);
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
execute p_update5('test_null',1,10);
--bypass
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
execute p_delete1 (1);
--nobypass
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
execute p_delete3(1,10);
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
execute p_delete4(1,10);
prepare p_delete2 as delete from test_bypass_sql_partition where true;
execute p_delete2;
reset enable_partition_opfusion;
drop table test_bypass_sql_partition;
--bypass
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
execute p_update1(1, 10);
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
execute p_update2('test_null',1,1);
--nobypass
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
update test_bypass_sql_partition set col3='test_null' where true;
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
execute p_update3(1,1,10);
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
execute p_update4('test_null',11,15);
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
execute p_update5('test_null',1,10);
--bypass
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
execute p_delete1 (1);
--nobypass
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
execute p_delete3(1,10);
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
execute p_delete4(1,10);
prepare p_delete2 as delete from test_bypass_sql_partition where true;
execute p_delete2;
reset enable_partition_opfusion;
drop table test_bypass_sql_partition;

View File

@ -7,6 +7,7 @@ set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
drop table if exists test_bypass_sq1;
create table test_bypass_sq1(col1 int, col2 int, col3 text);

View File

@ -7,6 +7,7 @@ set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
-- create table
drop table if exists test_bypass_sq1;

View File

@ -1,254 +1,255 @@
set enable_opfusion=on;
set enable_partition_opfusion=on;
set enable_bitmapscan=off;
set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
--create table
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
--insert
explain insert into test_bypass_sql_partition values (0,0,'test_insert');
insert into test_bypass_sql_partition values (0,0,'test_insert');
explain insert into test_bypass_sql_partition values (0,1,'test_insert');
insert into test_bypass_sql_partition values (0,1,'test_insert');
explain insert into test_bypass_sql_partition values (11,1,'test_insert');
insert into test_bypass_sql_partition values (11,1,'test_insert');
explain insert into test_bypass_sql_partition values (11,2,'test_insert');
insert into test_bypass_sql_partition values (11,2,'test_insert');
explain insert into test_bypass_sql_partition values (0,10,'test_insert2');
insert into test_bypass_sql_partition values (0,10,'test_insert2');
explain insert into test_bypass_sql_partition values (2,12,'test_insert2');
insert into test_bypass_sql_partition values (2,12,'test_insert2');
explain insert into test_bypass_sql_partition values (30,0,'test_insert3');
insert into test_bypass_sql_partition values (30,0,'test_insert3');
explain insert into test_bypass_sql_partition values (3,3,'test_insert3');
insert into test_bypass_sql_partition values (3,3,'test_insert3');
explain insert into test_bypass_sql_partition(col1,col2) values (1,1);
insert into test_bypass_sql_partition(col1,col2) values (1,1);
explain insert into test_bypass_sql_partition(col1,col2) values (22,2);
insert into test_bypass_sql_partition(col1,col2) values (22,2);
explain insert into test_bypass_sql_partition(col1,col2) values (33,3);
insert into test_bypass_sql_partition(col1,col2) values (33,3);
--error
explain insert into test_bypass_sql_partition values (null,null,null);
insert into test_bypass_sql_partition values (null,null,null);
--nobypass
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
--select
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
--bypass
set enable_indexonlyscan=off;
explain select * from test_bypass_sql_partition where col1=0 and col2=0;
select * from test_bypass_sql_partition where col1=0 and col2=0;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
explain select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
explain select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
explain select * from test_bypass_sql_partition where col1=0 and col2=-1;
select * from test_bypass_sql_partition where col1=0 and col2=-1;
reset enable_indexonlyscan;
--bypass though index only scan
set enable_indexscan = off;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
reset enable_indexscan;
--error
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
--nobypass
explain select * from test_bypass_sql_partition where col1 is null and col2 is null;
select * from test_bypass_sql_partition where col1 is null and col2 is null;
select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
--update
--bypass
explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=0 and col2=0;
update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=10 and col2=0;
explain update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
explain update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
--not bypass
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
explain select * from test_bypass_sql_partition where col3 is not null;
explain update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
--bypass
explain update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
explain select * from test_bypass_sql_partition where col1=0 order by col1;
select * from test_bypass_sql_partition where col1=0 order by col1;
explain select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
explain select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
--nobypass
explain select * from test_bypass_sql_partition where col2=20 order by col1;
select * from test_bypass_sql_partition where col2=20 order by col1;
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
explain select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
--bypass though index only scan
set enable_indexscan = off;
explain select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
--nobypass
explain select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
explain select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
reset enable_indexscan;
--nobypass
explain select * from test_bypass_sql_partition where col1>col2 limit 10;
explain select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
explain select * from test_bypass_sql_partition where col3='test_update2';
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset 3;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset null;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update offset 3;
explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
explain delete from test_bypass_sql_partition where col1=1 and col2=1;
delete from test_bypass_sql_partition where col1=1 and col2=1;
--error
explain delete from test_bypass_sql_partition where col1 is null and col2 is null;
delete from test_bypass_sql_partition where col1 is null and col2 is null;
explain insert into test_bypass_sql_partition values (null,null,null);
insert into test_bypass_sql_partition values (null,null,null);
--bypass / set enable_bitmapscan=off;
select * from test_bypass_sql_partition where col1=3;
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10 desc; --order by is supported when ordered col is in index
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
--not bypass
explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col2 desc limit 10;
--bypass
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10 ;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10;
--not bypass
explain select * from test_bypass_sql_partition where true;
explain select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
--bypass
select col2, col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc limit 10;
explain insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1=0;
delete from test_bypass_sql_partition where col1=1;
delete from test_bypass_sql_partition where col1 > 10 and col1 < 0;
delete from test_bypass_sql_partition where col1 <= 11 and col1 >= 15;
--nobypass
delete from test_bypass_sql_partition where col1 > 10;
delete from test_bypass_sql_partition where col1 < 10;
delete from test_bypass_sql_partition where col1 >= 10 and col1 <= 30;
reset enable_partition_opfusion;
drop table test_bypass_sql_partition;
set enable_opfusion=on;
set enable_partition_opfusion=on;
set enable_bitmapscan=off;
set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
--create table
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
--insert
explain insert into test_bypass_sql_partition values (0,0,'test_insert');
insert into test_bypass_sql_partition values (0,0,'test_insert');
explain insert into test_bypass_sql_partition values (0,1,'test_insert');
insert into test_bypass_sql_partition values (0,1,'test_insert');
explain insert into test_bypass_sql_partition values (11,1,'test_insert');
insert into test_bypass_sql_partition values (11,1,'test_insert');
explain insert into test_bypass_sql_partition values (11,2,'test_insert');
insert into test_bypass_sql_partition values (11,2,'test_insert');
explain insert into test_bypass_sql_partition values (0,10,'test_insert2');
insert into test_bypass_sql_partition values (0,10,'test_insert2');
explain insert into test_bypass_sql_partition values (2,12,'test_insert2');
insert into test_bypass_sql_partition values (2,12,'test_insert2');
explain insert into test_bypass_sql_partition values (30,0,'test_insert3');
insert into test_bypass_sql_partition values (30,0,'test_insert3');
explain insert into test_bypass_sql_partition values (3,3,'test_insert3');
insert into test_bypass_sql_partition values (3,3,'test_insert3');
explain insert into test_bypass_sql_partition(col1,col2) values (1,1);
insert into test_bypass_sql_partition(col1,col2) values (1,1);
explain insert into test_bypass_sql_partition(col1,col2) values (22,2);
insert into test_bypass_sql_partition(col1,col2) values (22,2);
explain insert into test_bypass_sql_partition(col1,col2) values (33,3);
insert into test_bypass_sql_partition(col1,col2) values (33,3);
--error
explain insert into test_bypass_sql_partition values (null,null,null);
insert into test_bypass_sql_partition values (null,null,null);
--nobypass
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
--select
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
--bypass
set enable_indexonlyscan=off;
explain select * from test_bypass_sql_partition where col1=0 and col2=0;
select * from test_bypass_sql_partition where col1=0 and col2=0;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
explain select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
explain select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
explain select * from test_bypass_sql_partition where col1=0 and col2=-1;
select * from test_bypass_sql_partition where col1=0 and col2=-1;
reset enable_indexonlyscan;
--bypass though index only scan
set enable_indexscan = off;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
reset enable_indexscan;
--error
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
--nobypass
explain select * from test_bypass_sql_partition where col1 is null and col2 is null;
select * from test_bypass_sql_partition where col1 is null and col2 is null;
select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
explain select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
--update
--bypass
explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=0 and col2=0;
update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=10 and col2=0;
explain update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
explain update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
--not bypass
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
explain select * from test_bypass_sql_partition where col3 is not null;
explain update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
--bypass
explain update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
explain select * from test_bypass_sql_partition where col1=0 order by col1;
select * from test_bypass_sql_partition where col1=0 order by col1;
explain select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
explain select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
--nobypass
explain select * from test_bypass_sql_partition where col2=20 order by col1;
select * from test_bypass_sql_partition where col2=20 order by col1;
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
explain select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
--bypass though index only scan
set enable_indexscan = off;
explain select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
--nobypass
explain select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
explain select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
reset enable_indexscan;
--nobypass
explain select * from test_bypass_sql_partition where col1>col2 limit 10;
explain select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
explain select * from test_bypass_sql_partition where col3='test_update2';
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset 3;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset null;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update offset 3;
explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
explain delete from test_bypass_sql_partition where col1=1 and col2=1;
delete from test_bypass_sql_partition where col1=1 and col2=1;
--error
explain delete from test_bypass_sql_partition where col1 is null and col2 is null;
delete from test_bypass_sql_partition where col1 is null and col2 is null;
explain insert into test_bypass_sql_partition values (null,null,null);
insert into test_bypass_sql_partition values (null,null,null);
--bypass / set enable_bitmapscan=off;
select * from test_bypass_sql_partition where col1=3;
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10 desc; --order by is supported when ordered col is in index
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
--not bypass
explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col2 desc limit 10;
--bypass
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10 ;
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10;
--not bypass
explain select * from test_bypass_sql_partition where true;
explain select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
--bypass
select col2, col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc limit 10;
explain insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1=0;
delete from test_bypass_sql_partition where col1=1;
delete from test_bypass_sql_partition where col1 > 10 and col1 < 0;
delete from test_bypass_sql_partition where col1 <= 11 and col1 >= 15;
--nobypass
delete from test_bypass_sql_partition where col1 > 10;
delete from test_bypass_sql_partition where col1 < 10;
delete from test_bypass_sql_partition where col1 >= 10 and col1 <= 30;
reset enable_partition_opfusion;
drop table test_bypass_sql_partition;

View File

@ -1,245 +1,246 @@
set enable_opfusion=on;
set enable_partition_opfusion=on;
set enable_bitmapscan=off;
set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
--create table
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
explain execute p11(0,0,'test_insert');
execute p11(10,10,'test_insert');
execute p11(12,12,'test_insert');
execute p11(-1,-1,'test_insert2');
execute p11(23,23,'test_insert2');
execute p11(33,33,'test_insert3');
execute p11(0,0,'test_insert3');
explain execute p12(1,1);
execute p12(1,1);
execute p12(22,22);
execute p12(20,20);
--nobypass
execute p11(null,null,null);
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
execute p_insert1;
--bypass
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
explain execute p13(0,0);
execute p13(0,0);
execute p13(10,0);
execute p13(20,0);
execute p13(30,0);
execute p13(40,0);
set enable_indexonlyscan=off;
explain execute p13(0,0);
execute p13(0,0);
reset enable_indexonlyscan;
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
explain execute p15 (0,0,'test_update',-1);
execute p15 (0,0,'test_update',-1);
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
explain execute p16(5,3,1,1);
execute p16(5,3,1,1);
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
execute p101 (111,'test_update2',-1);
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
execute p102 (1);
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
explain execute p1011;
execute p1011;
explain execute p1012;
execute p1012;
explain execute p1013;
execute p1013;
explain execute p1014;
execute p1014;
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
explain execute p10141;
execute p10141;
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p1021(1);
execute p1021(1);
--bypass through index only scan
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p10211(1);
execute p10211(1);
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
explain execute p10212(1);
execute p10212(1);
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
explain execute p10213(1);
execute p10213(1);
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
explain execute p10214(1);
execute p10214(1);
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
execute p1024;
execute p1025(1);
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
execute p104 (3);
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
execute p1052(2);
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
execute p10601 (0,10,1);
--nobypass
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
execute p1020;
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
explain execute p10200;
execute p10200;
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
explain execute p1022(0,3);
execute p1022(0,3);
explain execute p1022(0,null);
execute p1022(0,null);
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
explain execute p1023(0,3,2);
execute p1023(0,3,2);
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
explain execute p1026(0,3);
execute p1026(0,3);
explain execute p1027(0,3,2);
execute p1027(0,3,2);
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
execute p103 (2);
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
execute p105 (5);
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
execute p1051(5,3);
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
execute p106 (0,1);
--bypass
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
execute p17 (3,3);
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
explain execute p18(3,7,3,3);
execute p18(3,7,3,3);
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
execute p111;
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
execute p112;
--nobypass
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
explain execute p181(111);
execute p181(111);
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
execute p191;
execute p192;
--error
execute p11(null,null,'test_null');
--bypass through index only scan
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
explain execute p11301 (2);
execute p11301 (2);
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
explain execute p11401 (2);
execute p11401 (2);
set enable_indexonlyscan=off;
explain execute p11301 (2);
execute p11401 (2);
reset enable_indexonlyscan;
--nobypass
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
execute p120 (0, 9);
--not bypass
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
explain execute p115;
execute p115;
prepare p116 as select * from test_bypass_sql_partition order by col2;
explain execute p116;
execute p116;
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
execute p117;
execute p118;
execute p119;
--bypass
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
execute p_select1(0);
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
execute p_select2(0);
--nobypass
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
execute p_select3;
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
execute p_select4(20,10);
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
execute p_select5(11,15);
--bypass
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
execute p_update1(1, 10);
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
execute p_update2('test_null',1,1);
--nobypass
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
update test_bypass_sql_partition set col3='test_null' where true;
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
execute p_update3(1,1,10);
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
execute p_update4('test_null',11,15);
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
execute p_update5('test_null',1,10);
--bypass
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
execute p_delete1 (1);
--nobypass
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
execute p_delete3(1,10);
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
execute p_delete4(1,10);
prepare p_delete2 as delete from test_bypass_sql_partition where true;
execute p_delete2;
reset enable_partition_opfusion;
drop table test_bypass_sql_partition;
set enable_opfusion=on;
set enable_partition_opfusion=on;
set enable_bitmapscan=off;
set enable_seqscan=off;
set opfusion_debug_mode = 'log';
set log_min_messages=debug;
set logging_module = 'on(OPFUSION)';
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
--create table
drop table if exists test_bypass_sql_partition;
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
partition by range (col1)
(
partition test_bypass_sql_partition_1 values less than(10),
partition test_bypass_sql_partition_2 values less than(20),
partition test_bypass_sql_partition_3 values less than(30),
partition test_bypass_sql_partition_4 values less than(40),
partition test_bypass_sql_partition_5 values less than(50),
partition test_bypass_sql_partition_6 values less than(60),
partition test_bypass_sql_partition_7 values less than(70),
partition test_bypass_sql_partition_8 values less than(80)
);
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
explain execute p11(0,0,'test_insert');
execute p11(10,10,'test_insert');
execute p11(12,12,'test_insert');
execute p11(-1,-1,'test_insert2');
execute p11(23,23,'test_insert2');
execute p11(33,33,'test_insert3');
execute p11(0,0,'test_insert3');
explain execute p12(1,1);
execute p12(1,1);
execute p12(22,22);
execute p12(20,20);
--nobypass
execute p11(null,null,null);
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
execute p_insert1;
--bypass
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
explain execute p13(0,0);
execute p13(0,0);
execute p13(10,0);
execute p13(20,0);
execute p13(30,0);
execute p13(40,0);
set enable_indexonlyscan=off;
explain execute p13(0,0);
execute p13(0,0);
reset enable_indexonlyscan;
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
explain execute p15 (0,0,'test_update',-1);
execute p15 (0,0,'test_update',-1);
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
explain execute p16(5,3,1,1);
execute p16(5,3,1,1);
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
execute p101 (111,'test_update2',-1);
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
execute p102 (1);
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
explain execute p1011;
execute p1011;
explain execute p1012;
execute p1012;
explain execute p1013;
execute p1013;
explain execute p1014;
execute p1014;
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
explain execute p10141;
execute p10141;
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p1021(1);
execute p1021(1);
--bypass through index only scan
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
explain execute p10211(1);
execute p10211(1);
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
explain execute p10212(1);
execute p10212(1);
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
explain execute p10213(1);
execute p10213(1);
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
explain execute p10214(1);
execute p10214(1);
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
execute p1024;
execute p1025(1);
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
execute p104 (3);
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
execute p1052(2);
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
execute p10601 (0,10,1);
--nobypass
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
execute p1020;
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
explain execute p10200;
execute p10200;
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
explain execute p1022(0,3);
execute p1022(0,3);
explain execute p1022(0,null);
execute p1022(0,null);
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
explain execute p1023(0,3,2);
execute p1023(0,3,2);
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
explain execute p1026(0,3);
execute p1026(0,3);
explain execute p1027(0,3,2);
execute p1027(0,3,2);
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
execute p103 (2);
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
execute p105 (5);
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
execute p1051(5,3);
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
execute p106 (0,1);
--bypass
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
execute p17 (3,3);
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
explain execute p18(3,7,3,3);
execute p18(3,7,3,3);
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
execute p111;
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
execute p112;
--nobypass
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
explain execute p181(111);
execute p181(111);
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
execute p191;
execute p192;
--error
execute p11(null,null,'test_null');
--bypass through index only scan
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
explain execute p11301 (2);
execute p11301 (2);
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
explain execute p11401 (2);
execute p11401 (2);
set enable_indexonlyscan=off;
explain execute p11301 (2);
execute p11401 (2);
reset enable_indexonlyscan;
--nobypass
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
execute p120 (0, 9);
--not bypass
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
explain execute p115;
execute p115;
prepare p116 as select * from test_bypass_sql_partition order by col2;
explain execute p116;
execute p116;
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
execute p117;
execute p118;
execute p119;
--bypass
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
execute p_select1(0);
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
execute p_select2(0);
--nobypass
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
execute p_select3;
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
execute p_select4(20,10);
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
execute p_select5(11,15);
--bypass
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
execute p_update1(1, 10);
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
execute p_update2('test_null',1,1);
--nobypass
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
update test_bypass_sql_partition set col3='test_null' where true;
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
execute p_update3(1,1,10);
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
execute p_update4('test_null',11,15);
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
execute p_update5('test_null',1,10);
--bypass
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
execute p_delete1 (1);
--nobypass
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
execute p_delete3(1,10);
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
execute p_delete4(1,10);
prepare p_delete2 as delete from test_bypass_sql_partition where true;
execute p_delete2;
reset enable_partition_opfusion;
drop table test_bypass_sql_partition;