From 364f7eee63dfa8a999142f6b317e04237fa43acf Mon Sep 17 00:00:00 2001 From: wangfeihuo Date: Sat, 19 Apr 2025 11:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B4=E5=BD=A2=E4=B8=8Eun?= =?UTF-8?q?know=E6=AF=94=E8=BE=83=EF=BC=8C=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=B0=86unknow=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=88=90=E6=95=B4?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dolphin/expected/prepare_index_con.out | 1040 +++++++++++++++++ contrib/dolphin/expected/tpcc_plan.out | 504 ++++++++ contrib/dolphin/include/plugin_postgres.h | 1 + contrib/dolphin/parallel_schedule_dolphinB | 2 + contrib/dolphin/plugin_parser/parse_oper.cpp | 79 +- contrib/dolphin/plugin_postgres.cpp | 10 + contrib/dolphin/sql/prepare_index_con.sql | 311 +++++ contrib/dolphin/sql/tpcc_plan.sql | 276 +++++ 8 files changed, 2203 insertions(+), 20 deletions(-) create mode 100644 contrib/dolphin/expected/prepare_index_con.out create mode 100644 contrib/dolphin/expected/tpcc_plan.out create mode 100644 contrib/dolphin/sql/prepare_index_con.sql create mode 100644 contrib/dolphin/sql/tpcc_plan.sql diff --git a/contrib/dolphin/expected/prepare_index_con.out b/contrib/dolphin/expected/prepare_index_con.out new file mode 100644 index 000000000..7d581302e --- /dev/null +++ b/contrib/dolphin/expected/prepare_index_con.out @@ -0,0 +1,1040 @@ +create schema prepare_index_con; +set current_schema to 'prepare_index_con'; +create table test1(c1 int1, c2 int2, c3 int4, c4 int8, c5 uint1, c6 uint2, c7 uint4, c8 uint8); +insert into test1 values (generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100)); +create index idx1 on test1(c1); +create index idx2 on test1(c2); +create index idx3 on test1(c3); +create index idx4 on test1(c4); +create index idx5 on test1(c5); +create index idx6 on test1(c6); +create index idx7 on test1(c7); +create index idx8 on test1(c8); +create index idx9 on test1(c2, c3); +create index idx10 on test1(c2, c3, c4); +create index idx11 on test1(c4, c3, c2); +analyze test1; +set enable_seqscan = off; +set dolphin.transform_unknown_param_type_as_column_type_first = true; +prepare s1 as select * from test1 where c1 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx1 on test1 + Index Cond: (c1 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx1 on test1 + Index Cond: (c1 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c1; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx1 on test1 + Index Cond: ($1 = c1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx1 on test1 + Index Cond: ($1 = c1) +(3 rows) + +prepare s1 as select * from test1 where c2 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx10 on test1 + Index Cond: (c2 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx10 on test1 + Index Cond: (c2 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c2; +explain (costs off) execute s1 using 1; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx10 on test1 + Index Cond: ($1 = c2) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx10 on test1 + Index Cond: ($1 = c2) +(3 rows) + +prepare s1 as select * from test1 where c3 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx3 on test1 + Index Cond: (c3 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx3 on test1 + Index Cond: (c3 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c3; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx3 on test1 + Index Cond: ($1 = c3) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx3 on test1 + Index Cond: ($1 = c3) +(3 rows) + +prepare s1 as select * from test1 where c4 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: (c4 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: (c4 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c4; +explain (costs off) execute s1 using 1; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ($1 = c4) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +--------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ($1 = c4) +(3 rows) + +prepare s1 as select * from test1 where c5 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx5 on test1 + Index Cond: (c5 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx5 on test1 + Index Cond: (c5 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c5; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx5 on test1 + Index Cond: ($1 = c5) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx5 on test1 + Index Cond: ($1 = c5) +(3 rows) + +prepare s1 as select * from test1 where c6 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx6 on test1 + Index Cond: (c6 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx6 on test1 + Index Cond: (c6 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c6; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx6 on test1 + Index Cond: ($1 = c6) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx6 on test1 + Index Cond: ($1 = c6) +(3 rows) + +prepare s1 as select * from test1 where c7 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx7 on test1 + Index Cond: (c7 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx7 on test1 + Index Cond: (c7 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c7; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx7 on test1 + Index Cond: ($1 = c7) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx7 on test1 + Index Cond: ($1 = c7) +(3 rows) + +prepare s1 as select * from test1 where c8 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx8 on test1 + Index Cond: (c8 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx8 on test1 + Index Cond: (c8 = $1) +(3 rows) + +prepare s1 as select * from test1 where ? = c8; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx8 on test1 + Index Cond: ($1 = c8) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------- + [Bypass] + Index Scan using idx8 on test1 + Index Cond: ($1 = c8) +(3 rows) + +prepare s1 as select * from test1 where c2 = ? and c3 = ? and c4 = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ((c4 = $3) AND (c3 = $2) AND (c2 = $1)) +(3 rows) + +explain (costs off) execute s1 using 1.23, 1.23, 1.23; + QUERY PLAN +------------------------------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ((c4 = $3) AND (c3 = $2) AND (c2 = $1)) +(3 rows) + +prepare s1 as select * from test1 where c4 = ? and c3 = ? and c2 = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ((c4 = $1) AND (c3 = $2) AND (c2 = $3)) +(3 rows) + +explain (costs off) execute s1 using 1.23, 1.23, 1.23; + QUERY PLAN +------------------------------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ((c4 = $1) AND (c3 = $2) AND (c2 = $3)) +(3 rows) + +prepare s1 as select * from test1 where c2 = ? and c3 = ?; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +----------------------------------------- + [Bypass] + Index Scan using idx10 on test1 + Index Cond: ((c2 = $1) AND (c3 = $2)) +(3 rows) + +explain (costs off) execute s1 using 1.23, 1.23; + QUERY PLAN +----------------------------------------- + [Bypass] + Index Scan using idx10 on test1 + Index Cond: ((c2 = $1) AND (c3 = $2)) +(3 rows) + +prepare s1 as select * from test1 where c2 = ? and c4 = ?; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +----------------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ((c4 = $2) AND (c2 = $1)) +(3 rows) + +explain (costs off) execute s1 using 1.23, 1.23; + QUERY PLAN +----------------------------------------- + [Bypass] + Index Scan using idx11 on test1 + Index Cond: ((c4 = $2) AND (c2 = $1)) +(3 rows) + +prepare s1 as select * from test1 where c2 = ? + ? - ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + Seq Scan on test1 + Filter: ((c2)::double precision = (($1 + $2) - $3)) +(2 rows) + +explain (costs off) execute s1 using 1.23, 1.23, 1.23; + QUERY PLAN +------------------------------------------------------- + Seq Scan on test1 + Filter: ((c2)::double precision = (($1 + $2) - $3)) +(2 rows) + +create table test_type_table +( + a_int1 tinyint, + a_uint1 tinyint unsigned, + a_int2 smallint, + a_uint2 smallint unsigned, + a_int4 integer, + a_uint4 integer unsigned, + a_int8 bigint, + a_uint8 bigint unsigned, + a_float4 float4, + a_float8 float8, + a_numeric decimal(20, 6), + a_bit1 bit(1), + a_bit64 bit(64), + a_boolean boolean, + a_date date, + a_time time, + a_datetime datetime, + a_timestamp timestamp, + a_year year, + a_char char(100), + a_varchar varchar(100), + a_binary binary(100), + a_varbinary varbinary(100), + a_tinyblob tinyblob, + a_blob blob, + a_mediumblob mediumblob, + a_longblob longblob, + a_text text +); +insert into test_type_table values (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, b'1', b'111', true, '2023-02-05', '19:10:50', '2023-02-05 19:10:50', '2023-02-05 19:10:50', '2023', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a'); +create index a_id1 on test_type_table(a_int1); +create index a_id2 on test_type_table(a_uint1); +create index a_id3 on test_type_table(a_int2); +create index a_id4 on test_type_table(a_uint2); +create index a_id5 on test_type_table(a_int4); +create index a_id6 on test_type_table(a_uint4); +create index a_id7 on test_type_table(a_int8); +create index a_id8 on test_type_table(a_uint8); +create index a_id9 on test_type_table(a_float4); +create index a_id10 on test_type_table(a_float8); +create index a_id12 on test_type_table(a_numeric); +create index a_id13 on test_type_table(a_bit1); +create index a_id14 on test_type_table(a_bit64); +create index a_id15 on test_type_table(a_boolean); +create index a_id16 on test_type_table(a_date); +create index a_id17 on test_type_table(a_time); +create index a_id18 on test_type_table(a_datetime); +create index a_id18 on test_type_table(a_timestamp); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_timestamp_idx" +create index a_id18 on test_type_table(a_year); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_year_idx" +create index a_id18 on test_type_table(a_char); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_char_idx" +create index a_id18 on test_type_table(a_varchar); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_varchar_idx" +create index a_id18 on test_type_table(a_binary); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_binary_idx" +create index a_id18 on test_type_table(a_varbinary); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_varbinary_idx" +create index a_id18 on test_type_table(a_tinyblob); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_tinyblob_idx" +create index a_id18 on test_type_table(a_blob); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_blob_idx" +create index a_id18 on test_type_table(a_mediumblob); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_mediumblob_idx" +create index a_id18 on test_type_table(a_longblob); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_longblob_idx" +create index a_id18 on test_type_table(a_text); +WARNING: index "a_id18" already exists, change index name to "test_type_table_a_text_idx" +prepare s1 as select * from test_type_table where a_int1 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id1 on test_type_table + Index Cond: (a_int1 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id1 on test_type_table + Index Cond: (a_int1 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id1 on test_type_table + Index Cond: (a_int1 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_uint1 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id2 on test_type_table + Index Cond: (a_uint1 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id2 on test_type_table + Index Cond: (a_uint1 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id2 on test_type_table + Index Cond: (a_uint1 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_int2 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id3 on test_type_table + Index Cond: (a_int2 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id3 on test_type_table + Index Cond: (a_int2 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id3 on test_type_table + Index Cond: (a_int2 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_uint2 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id4 on test_type_table + Index Cond: (a_uint2 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id4 on test_type_table + Index Cond: (a_uint2 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id4 on test_type_table + Index Cond: (a_uint2 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_int4 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id5 on test_type_table + Index Cond: (a_int4 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id5 on test_type_table + Index Cond: (a_int4 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id5 on test_type_table + Index Cond: (a_int4 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_uint4 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id6 on test_type_table + Index Cond: (a_uint4 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id6 on test_type_table + Index Cond: (a_uint4 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id6 on test_type_table + Index Cond: (a_uint4 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_int8 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id7 on test_type_table + Index Cond: (a_int8 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id7 on test_type_table + Index Cond: (a_int8 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id7 on test_type_table + Index Cond: (a_int8 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_uint8 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id8 on test_type_table + Index Cond: (a_uint8 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id8 on test_type_table + Index Cond: (a_uint8 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id8 on test_type_table + Index Cond: (a_uint8 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_float4 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id9 on test_type_table + Index Cond: (a_float4 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id9 on test_type_table + Index Cond: (a_float4 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------- + [Bypass] + Index Scan using a_id9 on test_type_table + Index Cond: (a_float4 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_float8 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id10 on test_type_table + Index Cond: (a_float8 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id10 on test_type_table + Index Cond: (a_float8 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id10 on test_type_table + Index Cond: (a_float8 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_numeric = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id12 on test_type_table + Index Cond: (a_numeric = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id12 on test_type_table + Index Cond: (a_numeric = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id12 on test_type_table + Index Cond: (a_numeric = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_bit1 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id13 on test_type_table + Index Cond: (a_bit1 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id13 on test_type_table + Index Cond: (a_bit1 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id13 on test_type_table + Index Cond: (a_bit1 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_bit64 = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id14 on test_type_table + Index Cond: (a_bit64 = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id14 on test_type_table + Index Cond: (a_bit64 = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id14 on test_type_table + Index Cond: (a_bit64 = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_boolean = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id15 on test_type_table + Index Cond: (a_boolean = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id15 on test_type_table + Index Cond: (a_boolean = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id15 on test_type_table + Index Cond: (a_boolean = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_date = ?; +explain (costs off) execute s1 using '2024-10-10'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id16 on test_type_table + Index Cond: (a_date = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_datetime = ?; +explain (costs off) execute s1 using '2024-10-10 10:10:10'; + QUERY PLAN +-------------------------------------------- + [Bypass] + Index Scan using a_id18 on test_type_table + Index Cond: (a_datetime = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_timestamp = ?; +explain (costs off) execute s1 using '2024-10-10 10:10:10'; + QUERY PLAN +--------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_timestamp_idx on test_type_table + Index Cond: (a_timestamp = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_year = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_year_idx on test_type_table + Index Cond: (a_year = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_year_idx on test_type_table + Index Cond: (a_year = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_year_idx on test_type_table + Index Cond: (a_year = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_char = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_char_idx on test_type_table + Index Cond: (a_char = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_char_idx on test_type_table + Index Cond: (a_char = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_char_idx on test_type_table + Index Cond: (a_char = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_varchar = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_varchar_idx on test_type_table + Index Cond: ((a_varchar)::text = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_varchar_idx on test_type_table + Index Cond: ((a_varchar)::text = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_varchar_idx on test_type_table + Index Cond: ((a_varchar)::text = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_binary = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------------------------------------ + [Bypass] + Index Scan using test_type_table_a_binary_idx on test_type_table + Index Cond: (a_binary = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +------------------------------------------------------------------ + [Bypass] + Index Scan using test_type_table_a_binary_idx on test_type_table + Index Cond: (a_binary = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +------------------------------------------------------------------ + [Bypass] + Index Scan using test_type_table_a_binary_idx on test_type_table + Index Cond: (a_binary = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_varbinary = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +--------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_varbinary_idx on test_type_table + Index Cond: (a_varbinary = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +--------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_varbinary_idx on test_type_table + Index Cond: (a_varbinary = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +--------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_varbinary_idx on test_type_table + Index Cond: (a_varbinary = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_tinyblob = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_tinyblob_idx on test_type_table + Index Cond: (a_tinyblob = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_tinyblob_idx on test_type_table + Index Cond: (a_tinyblob = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_tinyblob_idx on test_type_table + Index Cond: (a_tinyblob = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_blob = ?; +explain (costs off) execute s1 using 1; +ERROR: parameter $1 of type integer cannot be coerced to the expected type blob +HINT: You will need to rewrite or cast the expression. +explain (costs off) execute s1 using 1.23; +ERROR: parameter $1 of type numeric cannot be coerced to the expected type blob +HINT: You will need to rewrite or cast the expression. +explain (costs off) execute s1 using '1'; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_blob_idx on test_type_table + Index Cond: (a_blob = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_longblob = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +-------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_longblob_idx on test_type_table + Index Cond: (a_longblob = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +-------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_longblob_idx on test_type_table + Index Cond: (a_longblob = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +-------------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_longblob_idx on test_type_table + Index Cond: (a_longblob = $1) +(3 rows) + +prepare s1 as select * from test_type_table where a_text = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_text_idx on test_type_table + Index Cond: (a_text = $1) +(3 rows) + +explain (costs off) execute s1 using 1.23; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_text_idx on test_type_table + Index Cond: (a_text = $1) +(3 rows) + +explain (costs off) execute s1 using '1'; + QUERY PLAN +---------------------------------------------------------------- + [Bypass] + Index Scan using test_type_table_a_text_idx on test_type_table + Index Cond: (a_text = $1) +(3 rows) + +drop table test_type_table; +drop schema prepare_index_con cascade; +NOTICE: drop cascades to table test1 +reset current_schema; diff --git a/contrib/dolphin/expected/tpcc_plan.out b/contrib/dolphin/expected/tpcc_plan.out new file mode 100644 index 000000000..36c7df096 --- /dev/null +++ b/contrib/dolphin/expected/tpcc_plan.out @@ -0,0 +1,504 @@ +create schema tpcc_plan; +set current_schema to 'tpcc_plan'; +drop table if exists warehouse; +NOTICE: table "warehouse" does not exist, skipping +create table warehouse ( +w_id smallint not null, +w_name varchar(10), +w_street_1 varchar(20), +w_street_2 varchar(20), +w_city varchar(20), +w_state char(2), +w_zip char(9), +w_tax decimal(4,2), +w_ytd decimal(12,2), +primary key (w_id) ) Engine=InnoDB; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "warehouse_pkey" for table "warehouse" +drop table if exists district; +NOTICE: table "district" does not exist, skipping +create table district ( +d_id tinyint not null, +d_w_id smallint not null, +d_name varchar(10), +d_street_1 varchar(20), +d_street_2 varchar(20), +d_city varchar(20), +d_state char(2), +d_zip char(9), +d_tax decimal(4,2), +d_ytd decimal(12,2), +d_next_o_id int, +primary key (d_w_id, d_id) ) Engine=InnoDB; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "district_pkey" for table "district" +drop table if exists customer; +NOTICE: table "customer" does not exist, skipping +create table customer ( +c_id int not null, +c_d_id tinyint not null, +c_w_id smallint not null, +c_first varchar(16), +c_middle char(2), +c_last varchar(16), +c_street_1 varchar(20), +c_street_2 varchar(20), +c_city varchar(20), +c_state char(2), +c_zip char(9), +c_phone char(16), +c_since datetime, +c_credit char(2), +c_credit_lim bigint, +c_discount decimal(4,2), +c_balance decimal(12,2), +c_ytd_payment decimal(12,2), +c_payment_cnt smallint, +c_delivery_cnt smallint, +c_data text, +PRIMARY KEY(c_w_id, c_d_id, c_id) ) Engine=InnoDB; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "customer_pkey" for table "customer" +drop table if exists history; +NOTICE: table "history" does not exist, skipping +create table history ( +h_c_id int, +h_c_d_id tinyint, +h_c_w_id smallint, +h_d_id tinyint, +h_w_id smallint, +h_date datetime, +h_amount decimal(6,2), +h_data varchar(24) ) Engine=InnoDB; +drop table if exists new_orders; +NOTICE: table "new_orders" does not exist, skipping +create table new_orders ( +no_o_id int not null, +no_d_id tinyint not null, +no_w_id smallint not null, +PRIMARY KEY(no_w_id, no_d_id, no_o_id)) Engine=InnoDB; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "new_orders_pkey" for table "new_orders" +drop table if exists orders; +NOTICE: table "orders" does not exist, skipping +create table orders ( +o_id int not null, +o_d_id tinyint not null, +o_w_id smallint not null, +o_c_id int, +o_entry_d datetime, +o_carrier_id tinyint, +o_ol_cnt tinyint, +o_all_local tinyint, +PRIMARY KEY(o_w_id, o_d_id, o_id) ) Engine=InnoDB ; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "orders_pkey" for table "orders" +drop table if exists order_line; +NOTICE: table "order_line" does not exist, skipping +create table order_line ( +ol_o_id int not null, +ol_d_id tinyint not null, +ol_w_id smallint not null, +ol_number tinyint not null, +ol_i_id int, +ol_supply_w_id smallint, +ol_delivery_d datetime, +ol_quantity tinyint, +ol_amount decimal(6,2), +ol_dist_info char(24), +PRIMARY KEY(ol_w_id, ol_d_id, ol_o_id, ol_number) ) Engine=InnoDB ; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "order_line_pkey" for table "order_line" +drop table if exists item; +NOTICE: table "item" does not exist, skipping +create table item ( +i_id int not null, +i_im_id int, +i_name varchar(24), +i_price decimal(5,2), +i_data varchar(50), +PRIMARY KEY(i_id) ) Engine=InnoDB; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "item_pkey" for table "item" +drop table if exists stock; +NOTICE: table "stock" does not exist, skipping +create table stock ( +s_i_id int not null, +s_w_id smallint not null, +s_quantity smallint, +s_dist_01 char(24), +s_dist_02 char(24), +s_dist_03 char(24), +s_dist_04 char(24), +s_dist_05 char(24), +s_dist_06 char(24), +s_dist_07 char(24), +s_dist_08 char(24), +s_dist_09 char(24), +s_dist_10 char(24), +s_ytd decimal(8,0), +s_order_cnt smallint, +s_remote_cnt smallint, +s_data varchar(50), +PRIMARY KEY(s_w_id, s_i_id) ) Engine=InnoDB ; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "stock_pkey" for table "stock" +analyze customer; +analyze district; +analyze history; +analyze item; +analyze new_orders; +analyze order_line; +analyze orders; +analyze stock; +analyze warehouse; +set enable_seqscan = off; +set dolphin.transform_unknown_param_type_as_column_type_first = true; +prepare s1 as SELECT c_discount, c_last, c_credit, w_tax FROM customer, warehouse WHERE w_id = ? AND c_w_id = w_id AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------------------------- + Nested Loop + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2) AND (c_id = $3)) + -> Index Scan using warehouse_pkey on warehouse + Index Cond: (w_id = $1) +(5 rows) + +prepare s1 as SELECT d_next_o_id, d_tax FROM district WHERE d_id = ? AND d_w_id = ? FOR UPDATE; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +----------------------------------------------------- + [Bypass] + LockRows + -> Index Scan using district_pkey on district + Index Cond: ((d_w_id = $2) AND (d_id = $1)) +(4 rows) + +prepare s1 as UPDATE district SET d_next_o_id = ? + 1 WHERE d_id = ? AND d_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------- + [Bypass] + Update on district + -> Index Scan using district_pkey on district + Index Cond: ((d_w_id = $3) AND (d_id = $2)) +(4 rows) + +prepare s1 as INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) VALUES(?, ?, ?, ?, ?, ?, ?); +explain (costs off) execute s1 using 1, 2, 3, 4, '2024-10-10 10:10:10', 6, 7; + QUERY PLAN +------------------ + [Bypass] + Insert on orders + -> Result +(3 rows) + +prepare s1 as INSERT INTO new_orders (no_o_id, no_d_id, no_w_id) VALUES (?,?,?); +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +---------------------- + [Bypass] + Insert on new_orders + -> Result +(3 rows) + +prepare s1 as SELECT i_price, i_name, i_data FROM item WHERE i_id = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +------------------------------------ + [Bypass] + Index Scan using item_pkey on item + Index Cond: (i_id = $1) +(3 rows) + +prepare s1 as SELECT s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 FROM stock WHERE s_i_id = ? AND s_w_id = ? FOR UPDATE; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +------------------------------------------------------- + [Bypass] + LockRows + -> Index Scan using stock_pkey on stock + Index Cond: ((s_w_id = $2) AND (s_i_id = $1)) +(4 rows) + +prepare s1 as UPDATE stock SET s_quantity = ? WHERE s_i_id = ? AND s_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + [Bypass] + Update on stock + -> Index Scan using stock_pkey on stock + Index Cond: ((s_w_id = $3) AND (s_i_id = $2)) +(4 rows) + +prepare s1 as INSERT INTO order_line (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); +explain (costs off) execute s1 using 1, 2, 3, 4, 5, 6, 7, 8, 9; + QUERY PLAN +---------------------- + [Bypass] + Insert on order_line + -> Result +(3 rows) + +prepare s1 as UPDATE warehouse SET w_ytd = w_ytd + ? WHERE w_id = ?; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +---------------------------------------------------- + [Bypass] + Update on warehouse + -> Index Scan using warehouse_pkey on warehouse + Index Cond: (w_id = $2) +(4 rows) + +prepare s1 as SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name FROM warehouse WHERE w_id = ?; +explain (costs off) execute s1 using 1; + QUERY PLAN +---------------------------------------------- + [Bypass] + Index Scan using warehouse_pkey on warehouse + Index Cond: (w_id = $1) +(3 rows) + +prepare s1 as UPDATE district SET d_ytd = d_ytd + ? WHERE d_w_id = ? AND d_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------- + [Bypass] + Update on district + -> Index Scan using district_pkey on district + Index Cond: ((d_w_id = $2) AND (d_id = $3)) +(4 rows) + +prepare s1 as SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name FROM district WHERE d_w_id = ? AND d_id = ?; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +----------------------------------------------- + [Bypass] + Index Scan using district_pkey on district + Index Cond: ((d_w_id = $1) AND (d_id = $2)) +(3 rows) + +prepare s1 as SELECT count(c_id) FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + Aggregate + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2)) + Filter: ((c_last)::text = $3) +(4 rows) + +prepare s1 as SELECT c_id FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? ORDER BY c_id; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------- + Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2)) + Filter: ((c_last)::text = $3) +(3 rows) + +prepare s1 as SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_since FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ? FOR UPDATE; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------------------------- + [Bypass] + LockRows + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2) AND (c_id = $3)) +(4 rows) + +prepare s1 as SELECT c_data FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------------------- + [Bypass] + Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2) AND (c_id = $3)) +(3 rows) + +prepare s1 as UPDATE customer SET c_balance = ?, c_data = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4, 5; + QUERY PLAN +----------------------------------------------------------------------- + [Bypass] + Update on customer + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $3) AND (c_d_id = $4) AND (c_id = $5)) +(4 rows) + +prepare s1 as UPDATE customer SET c_balance = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4; + QUERY PLAN +----------------------------------------------------------------------- + [Bypass] + Update on customer + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $2) AND (c_d_id = $3) AND (c_id = $4)) +(4 rows) + +prepare s1 as INSERT INTO history(h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES(?, ?, ?, ?, ?, ?, ?, ?); +explain (costs off) execute s1 using 1, 2, 3, 4, 5, '2024-10-10 10:10:10', 7, 8; + QUERY PLAN +------------------- + [Bypass] + Insert on history + -> Result +(3 rows) + +prepare s1 as SELECT count(c_id) FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + Aggregate + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2)) + Filter: ((c_last)::text = $3) +(4 rows) + +prepare s1 as SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? ORDER BY c_first; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + Sort + Sort Key: c_first NULLS FIRST + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2)) + Filter: ((c_last)::text = $3) +(5 rows) + +prepare s1 as SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------------------- + [Bypass] + Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $1) AND (c_d_id = $2) AND (c_id = $3)) +(3 rows) + +prepare s1 as SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0) FROM orders WHERE o_w_id = ? AND o_d_id = ? AND o_c_id = ? AND o_id = (SELECT MAX(o_id) FROM orders WHERE o_w_id = ? AND o_d_id = ? AND o_c_id = ?); +explain (costs off) execute s1 using 1, 2, 3, 4, 5, 6; + QUERY PLAN +----------------------------------------------------------------------- + Index Scan using orders_pkey on orders + Index Cond: ((o_w_id = $1) AND (o_d_id = $2) AND (o_id = $1)) + Filter: (o_c_id = $3) + InitPlan 2 (returns $1) + -> Result + InitPlan 1 (returns $0) + -> Limit + -> Index Scan Backward using orders_pkey on orders + Index Cond: ((o_w_id = $4) AND (o_d_id = $5)) + Filter: (o_c_id = $6) +(10 rows) + +prepare s1 as SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d FROM order_line WHERE ol_w_id = ? AND ol_d_id = ? AND ol_o_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +---------------------------------------------------------------------- + [Bypass] + Index Scan using order_line_pkey on order_line + Index Cond: ((ol_w_id = $1) AND (ol_d_id = $2) AND (ol_o_id = $3)) +(3 rows) + +prepare s1 as SELECT COALESCE(MIN(no_o_id),0) FROM new_orders WHERE no_d_id = ? AND no_w_id = ?; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +------------------------------------------------------------------- + Result + InitPlan 1 (returns $0) + -> Limit + -> Index Only Scan using new_orders_pkey on new_orders + Index Cond: ((no_w_id = $2) AND (no_d_id = $1)) +(5 rows) + +prepare s1 as DELETE FROM new_orders WHERE no_o_id = ? AND no_d_id = ? AND no_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +---------------------------------------------------------------------------- + [Bypass] + Delete on new_orders + -> Index Scan using new_orders_pkey on new_orders + Index Cond: ((no_w_id = $3) AND (no_d_id = $2) AND (no_o_id = $1)) +(4 rows) + +prepare s1 as SELECT o_c_id FROM orders WHERE o_id = ? AND o_d_id = ? AND o_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +----------------------------------------------------------------- + [Bypass] + Index Scan using orders_pkey on orders + Index Cond: ((o_w_id = $3) AND (o_d_id = $2) AND (o_id = $1)) +(3 rows) + +prepare s1 as UPDATE orders SET o_carrier_id = ? WHERE o_id = ? AND o_d_id = ? AND o_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4; + QUERY PLAN +----------------------------------------------------------------------- + [Bypass] + Update on orders + -> Index Scan using orders_pkey on orders + Index Cond: ((o_w_id = $4) AND (o_d_id = $3) AND (o_id = $2)) +(4 rows) + +prepare s1 as UPDATE order_line SET ol_delivery_d = ? WHERE ol_o_id = ? AND ol_d_id = ? AND ol_w_id = ?; +explain (costs off) execute s1 using '2024-10-10 10:10:10', 2, 3, 4; + QUERY PLAN +---------------------------------------------------------------------------- + [Bypass] + Update on order_line + -> Index Scan using order_line_pkey on order_line + Index Cond: ((ol_w_id = $4) AND (ol_d_id = $3) AND (ol_o_id = $2)) +(4 rows) + +prepare s1 as SELECT SUM(ol_amount) FROM order_line WHERE ol_o_id = ? AND ol_d_id = ? AND ol_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +---------------------------------------------------------------------------- + Aggregate + -> Index Scan using order_line_pkey on order_line + Index Cond: ((ol_w_id = $3) AND (ol_d_id = $2) AND (ol_o_id = $1)) +(3 rows) + +prepare s1 as UPDATE customer SET c_balance = c_balance + ? , c_delivery_cnt = c_delivery_cnt + 1 WHERE c_id = ? AND c_d_id = ? AND c_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4; + QUERY PLAN +----------------------------------------------------------------------- + Update on customer + -> Index Scan using customer_pkey on customer + Index Cond: ((c_w_id = $4) AND (c_d_id = $3) AND (c_id = $2)) +(3 rows) + +prepare s1 as SELECT d_next_o_id FROM district WHERE d_id = ? AND d_w_id = ?; +explain (costs off) execute s1 using 1, 2; + QUERY PLAN +----------------------------------------------- + [Bypass] + Index Scan using district_pkey on district + Index Cond: ((d_w_id = $2) AND (d_id = $1)) +(3 rows) + +prepare s1 as SELECT DISTINCT ol_i_id FROM order_line WHERE ol_w_id = ? AND ol_d_id = ? AND ol_o_id < ? AND ol_o_id >= (? - 20); +explain (costs off) execute s1 using 1, 2, 3, 4; + QUERY PLAN +------------------------------------------------------------------------------ + HashAggregate + Group By Key: ol_i_id + -> Index Scan using order_line_pkey on order_line + Index Cond: ((ol_w_id = $1) AND (ol_d_id = $2) AND (ol_o_id < $3)) + Filter: ((ol_o_id)::double precision >= ($4 - 20::double precision)) +(5 rows) + +prepare s1 as SELECT count(*) FROM stock WHERE s_w_id = ? AND s_i_id = ? AND s_quantity < ?; +explain (costs off) execute s1 using 1, 2, 3; + QUERY PLAN +------------------------------------------------------- + Aggregate + -> Index Scan using stock_pkey on stock + Index Cond: ((s_w_id = $1) AND (s_i_id = $2)) + Filter: (s_quantity < $3) +(4 rows) + +drop table customer; +drop table district; +drop table history; +drop table item; +drop table new_orders; +drop table order_line; +drop table orders; +drop table stock; +drop table warehouse; +drop schema tpcc_plan cascade; +reset current_schema; diff --git a/contrib/dolphin/include/plugin_postgres.h b/contrib/dolphin/include/plugin_postgres.h index 114e12857..d86c675b1 100644 --- a/contrib/dolphin/include/plugin_postgres.h +++ b/contrib/dolphin/include/plugin_postgres.h @@ -200,6 +200,7 @@ typedef struct BSqlPluginContext { bool use_const_value_as_colname; bool support_interval_to; bool treat_float_with_precision_as_float_type; + bool transform_unknown_param_type_as_column_type_first; bool is_set_stmt; #endif } bSqlPluginContext; diff --git a/contrib/dolphin/parallel_schedule_dolphinB b/contrib/dolphin/parallel_schedule_dolphinB index 838472281..bc3f38529 100644 --- a/contrib/dolphin/parallel_schedule_dolphinB +++ b/contrib/dolphin/parallel_schedule_dolphinB @@ -91,3 +91,5 @@ test: test_row_in test_std test_var_pop b_database_subquery test_lag_lead builti test: db_b_parser2 test_shows_1 test_charset_collate charset_utf8mb4_b_db charset_gbk_b_db test_binary2 like_index_test_gbk like_index_test_gb18030 builtin_funcs/char_length builtin_funcs/character_length test: in_test eq_all_subquery alter_tables + +test: prepare_index_con tpcc_plan diff --git a/contrib/dolphin/plugin_parser/parse_oper.cpp b/contrib/dolphin/plugin_parser/parse_oper.cpp index 5a30448a7..befe9e5d7 100644 --- a/contrib/dolphin/plugin_parser/parse_oper.cpp +++ b/contrib/dolphin/plugin_parser/parse_oper.cpp @@ -541,7 +541,6 @@ inline bool IsString(Oid typeoid) return ((typeoid == BPCHAROID) || (typeoid == VARCHAROID) || (typeoid == NVARCHAR2OID) || (typeoid == CLOBOID) || (typeoid == TEXTOID) || (typeoid == UNKNOWNOID) || (typeoid == BINARYOID) || (typeoid == VARBINARYOID)); } - #endif /* oper() -- search for a binary operator @@ -992,6 +991,40 @@ Node* parse_get_last_srf(ParseState* pstate) return NULL; } +#ifdef DOLPHIN +/* + * coerce_param_to_column_type + * + * for case where column = ?, parse ? as column type. + * + */ +bool coerce_param_to_column_type(ParseState* pstate, Node* ltree, Node* rtree, Oid* ltypeId, Oid* rtypeId) +{ + if (!GetSessionContext()->transform_unknown_param_type_as_column_type_first) { + return false; + } + + /* do nothing */ + if (*ltypeId == *rtypeId) { + return false; + } + + /* left is column and right is param */ + if (IsA(ltree, Var) && IsA(rtree, Param) && ((Param*)rtree)->paramtype == UNKNOWNOID) { + *rtypeId = *ltypeId; + return true; + } + + /* left is param and right is column */ + if (IsA(rtree, Var) && IsA(ltree, Param) && ((Param*)ltree)->paramtype == UNKNOWNOID) { + *ltypeId = *rtypeId; + return true; + } + + return false; +} +#endif + /* * Operator expression construction. * @@ -1087,28 +1120,34 @@ Expr* make_op(ParseState* pstate, List* opname, Node* ltree, Node* rtree, Node* } } #ifdef DOLPHIN - info.pstate = pstate; - info.opname = opname; - info.ltypeId = ltypeId; - info.rtypeId = rtypeId; - info.ltree = ltree; - info.rtree = rtree; - info.location = location; - info.inNumeric = inNumeric; - tup = GetDolphinOperatorTup(&info); - if (!HeapTupleIsValid(tup)) { - if ((IsJsonType(ltypeId) || IsJsonType(rtypeId)) && ENABLE_B_CMPT_MODE) { - DeconstructQualifiedName(opname, &schemaname, &opername); - jsonTransfored = TransformJsonDolphinType(opername, ltypeId, rtypeId); - } + if (coerce_param_to_column_type(pstate, ltree, rtree, <ypeId, &rtypeId)) { tup = oper(pstate, opname, ltypeId, rtypeId, false, location, inNumeric); - if (jsonTransfored && HeapTupleIsValid(tup)) { - newLeftTree = CreateCastForType(pstate, info.ltypeId, info.ltree, tup, location, true); - newRightTree = CreateCastForType(pstate, info.rtypeId, info.rtree, tup, location, false); - } - } else { newLeftTree = CreateCastForType(pstate, ltypeId, ltree, tup, location, true); newRightTree = CreateCastForType(pstate, rtypeId, rtree, tup, location, false); + } else { + info.pstate = pstate; + info.opname = opname; + info.ltypeId = ltypeId; + info.rtypeId = rtypeId; + info.ltree = ltree; + info.rtree = rtree; + info.location = location; + info.inNumeric = inNumeric; + tup = GetDolphinOperatorTup(&info); + if (!HeapTupleIsValid(tup)) { + if ((IsJsonType(ltypeId) || IsJsonType(rtypeId)) && ENABLE_B_CMPT_MODE) { + DeconstructQualifiedName(opname, &schemaname, &opername); + jsonTransfored = TransformJsonDolphinType(opername, ltypeId, rtypeId); + } + tup = oper(pstate, opname, ltypeId, rtypeId, false, location, inNumeric); + if (jsonTransfored && HeapTupleIsValid(tup)) { + newLeftTree = CreateCastForType(pstate, info.ltypeId, info.ltree, tup, location, true); + newRightTree = CreateCastForType(pstate, info.rtypeId, info.rtree, tup, location, false); + } + } else { + newLeftTree = CreateCastForType(pstate, ltypeId, ltree, tup, location, true); + newRightTree = CreateCastForType(pstate, rtypeId, rtree, tup, location, false); + } } #else tup = oper(pstate, opname, ltypeId, rtypeId, false, location, inNumeric); diff --git a/contrib/dolphin/plugin_postgres.cpp b/contrib/dolphin/plugin_postgres.cpp index cda2a33ac..790993515 100644 --- a/contrib/dolphin/plugin_postgres.cpp +++ b/contrib/dolphin/plugin_postgres.cpp @@ -1474,6 +1474,16 @@ void init_session_vars(void) PGC_USERSET, 0, NULL, NULL, NULL); + DefineCustomBoolVariable("dolphin.transform_unknown_param_type_as_column_type_first", + gettext_noop("This variable indicates parsing the unknown param type to column type first." + "for example, parse ? as c1 type for predicate where c1 = ?," + "to avoid index unavailable caused by implicit."), + NULL, + &GetSessionContext()->transform_unknown_param_type_as_column_type_first, + false, + PGC_USERSET, + 0, + NULL, NULL, NULL); #endif } diff --git a/contrib/dolphin/sql/prepare_index_con.sql b/contrib/dolphin/sql/prepare_index_con.sql new file mode 100644 index 000000000..b3ab51226 --- /dev/null +++ b/contrib/dolphin/sql/prepare_index_con.sql @@ -0,0 +1,311 @@ +create schema prepare_index_con; +set current_schema to 'prepare_index_con'; + +create table test1(c1 int1, c2 int2, c3 int4, c4 int8, c5 uint1, c6 uint2, c7 uint4, c8 uint8); + +insert into test1 values (generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100), generate_series(0, 100)); + + +create index idx1 on test1(c1); +create index idx2 on test1(c2); +create index idx3 on test1(c3); +create index idx4 on test1(c4); +create index idx5 on test1(c5); +create index idx6 on test1(c6); +create index idx7 on test1(c7); +create index idx8 on test1(c8); +create index idx9 on test1(c2, c3); +create index idx10 on test1(c2, c3, c4); +create index idx11 on test1(c4, c3, c2); +analyze test1; + +set enable_seqscan = off; +set dolphin.transform_unknown_param_type_as_column_type_first = true; + +prepare s1 as select * from test1 where c1 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c1; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c2 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c2; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c3 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c3; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c4 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c4; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c5 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c5; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c6 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c6; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c7 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c7; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where c8 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + +prepare s1 as select * from test1 where ? = c8; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; + + +prepare s1 as select * from test1 where c2 = ? and c3 = ? and c4 = ?; +explain (costs off) execute s1 using 1, 2, 3; +explain (costs off) execute s1 using 1.23, 1.23, 1.23; + +prepare s1 as select * from test1 where c4 = ? and c3 = ? and c2 = ?; +explain (costs off) execute s1 using 1, 2, 3; +explain (costs off) execute s1 using 1.23, 1.23, 1.23; + +prepare s1 as select * from test1 where c2 = ? and c3 = ?; +explain (costs off) execute s1 using 1, 2; +explain (costs off) execute s1 using 1.23, 1.23; + + +prepare s1 as select * from test1 where c2 = ? and c4 = ?; +explain (costs off) execute s1 using 1, 2; +explain (costs off) execute s1 using 1.23, 1.23; + + +prepare s1 as select * from test1 where c2 = ? + ? - ?; +explain (costs off) execute s1 using 1, 2, 3; +explain (costs off) execute s1 using 1.23, 1.23, 1.23; + + + +create table test_type_table +( + a_int1 tinyint, + a_uint1 tinyint unsigned, + a_int2 smallint, + a_uint2 smallint unsigned, + a_int4 integer, + a_uint4 integer unsigned, + a_int8 bigint, + a_uint8 bigint unsigned, + a_float4 float4, + a_float8 float8, + a_numeric decimal(20, 6), + a_bit1 bit(1), + a_bit64 bit(64), + a_boolean boolean, + a_date date, + a_time time, + a_datetime datetime, + a_timestamp timestamp, + a_year year, + a_char char(100), + a_varchar varchar(100), + a_binary binary(100), + a_varbinary varbinary(100), + a_tinyblob tinyblob, + a_blob blob, + a_mediumblob mediumblob, + a_longblob longblob, + a_text text +); + +insert into test_type_table values (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, b'1', b'111', true, '2023-02-05', '19:10:50', '2023-02-05 19:10:50', '2023-02-05 19:10:50', '2023', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a', '1.23a'); + + +create index a_id1 on test_type_table(a_int1); +create index a_id2 on test_type_table(a_uint1); +create index a_id3 on test_type_table(a_int2); +create index a_id4 on test_type_table(a_uint2); +create index a_id5 on test_type_table(a_int4); +create index a_id6 on test_type_table(a_uint4); +create index a_id7 on test_type_table(a_int8); +create index a_id8 on test_type_table(a_uint8); +create index a_id9 on test_type_table(a_float4); +create index a_id10 on test_type_table(a_float8); +create index a_id12 on test_type_table(a_numeric); +create index a_id13 on test_type_table(a_bit1); +create index a_id14 on test_type_table(a_bit64); +create index a_id15 on test_type_table(a_boolean); +create index a_id16 on test_type_table(a_date); +create index a_id17 on test_type_table(a_time); +create index a_id18 on test_type_table(a_datetime); +create index a_id18 on test_type_table(a_timestamp); +create index a_id18 on test_type_table(a_year); +create index a_id18 on test_type_table(a_char); +create index a_id18 on test_type_table(a_varchar); +create index a_id18 on test_type_table(a_binary); +create index a_id18 on test_type_table(a_varbinary); +create index a_id18 on test_type_table(a_tinyblob); +create index a_id18 on test_type_table(a_blob); +create index a_id18 on test_type_table(a_mediumblob); +create index a_id18 on test_type_table(a_longblob); +create index a_id18 on test_type_table(a_text); + + +prepare s1 as select * from test_type_table where a_int1 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_uint1 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_int2 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_uint2 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + + +prepare s1 as select * from test_type_table where a_int4 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_uint4 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_int8 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + + +prepare s1 as select * from test_type_table where a_uint8 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_float4 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_float8 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_numeric = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_bit1 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_bit64 = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_boolean = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_date = ?; +explain (costs off) execute s1 using '2024-10-10'; + +prepare s1 as select * from test_type_table where a_datetime = ?; +explain (costs off) execute s1 using '2024-10-10 10:10:10'; + +prepare s1 as select * from test_type_table where a_timestamp = ?; +explain (costs off) execute s1 using '2024-10-10 10:10:10'; + +prepare s1 as select * from test_type_table where a_year = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_char = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_varchar = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_binary = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_varbinary = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_tinyblob = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + + +prepare s1 as select * from test_type_table where a_blob = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +prepare s1 as select * from test_type_table where a_longblob = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + + +prepare s1 as select * from test_type_table where a_text = ?; +explain (costs off) execute s1 using 1; +explain (costs off) execute s1 using 1.23; +explain (costs off) execute s1 using '1'; + +drop table test_type_table; + +drop schema prepare_index_con cascade; +reset current_schema; + diff --git a/contrib/dolphin/sql/tpcc_plan.sql b/contrib/dolphin/sql/tpcc_plan.sql new file mode 100644 index 000000000..7bcbd5a51 --- /dev/null +++ b/contrib/dolphin/sql/tpcc_plan.sql @@ -0,0 +1,276 @@ +create schema tpcc_plan; +set current_schema to 'tpcc_plan'; + +drop table if exists warehouse; + +create table warehouse ( +w_id smallint not null, +w_name varchar(10), +w_street_1 varchar(20), +w_street_2 varchar(20), +w_city varchar(20), +w_state char(2), +w_zip char(9), +w_tax decimal(4,2), +w_ytd decimal(12,2), +primary key (w_id) ) Engine=InnoDB; + +drop table if exists district; + +create table district ( +d_id tinyint not null, +d_w_id smallint not null, +d_name varchar(10), +d_street_1 varchar(20), +d_street_2 varchar(20), +d_city varchar(20), +d_state char(2), +d_zip char(9), +d_tax decimal(4,2), +d_ytd decimal(12,2), +d_next_o_id int, +primary key (d_w_id, d_id) ) Engine=InnoDB; + +drop table if exists customer; + +create table customer ( +c_id int not null, +c_d_id tinyint not null, +c_w_id smallint not null, +c_first varchar(16), +c_middle char(2), +c_last varchar(16), +c_street_1 varchar(20), +c_street_2 varchar(20), +c_city varchar(20), +c_state char(2), +c_zip char(9), +c_phone char(16), +c_since datetime, +c_credit char(2), +c_credit_lim bigint, +c_discount decimal(4,2), +c_balance decimal(12,2), +c_ytd_payment decimal(12,2), +c_payment_cnt smallint, +c_delivery_cnt smallint, +c_data text, +PRIMARY KEY(c_w_id, c_d_id, c_id) ) Engine=InnoDB; + +drop table if exists history; + +create table history ( +h_c_id int, +h_c_d_id tinyint, +h_c_w_id smallint, +h_d_id tinyint, +h_w_id smallint, +h_date datetime, +h_amount decimal(6,2), +h_data varchar(24) ) Engine=InnoDB; + +drop table if exists new_orders; + +create table new_orders ( +no_o_id int not null, +no_d_id tinyint not null, +no_w_id smallint not null, +PRIMARY KEY(no_w_id, no_d_id, no_o_id)) Engine=InnoDB; + +drop table if exists orders; + +create table orders ( +o_id int not null, +o_d_id tinyint not null, +o_w_id smallint not null, +o_c_id int, +o_entry_d datetime, +o_carrier_id tinyint, +o_ol_cnt tinyint, +o_all_local tinyint, +PRIMARY KEY(o_w_id, o_d_id, o_id) ) Engine=InnoDB ; + +drop table if exists order_line; + +create table order_line ( +ol_o_id int not null, +ol_d_id tinyint not null, +ol_w_id smallint not null, +ol_number tinyint not null, +ol_i_id int, +ol_supply_w_id smallint, +ol_delivery_d datetime, +ol_quantity tinyint, +ol_amount decimal(6,2), +ol_dist_info char(24), +PRIMARY KEY(ol_w_id, ol_d_id, ol_o_id, ol_number) ) Engine=InnoDB ; + +drop table if exists item; + +create table item ( +i_id int not null, +i_im_id int, +i_name varchar(24), +i_price decimal(5,2), +i_data varchar(50), +PRIMARY KEY(i_id) ) Engine=InnoDB; + +drop table if exists stock; + +create table stock ( +s_i_id int not null, +s_w_id smallint not null, +s_quantity smallint, +s_dist_01 char(24), +s_dist_02 char(24), +s_dist_03 char(24), +s_dist_04 char(24), +s_dist_05 char(24), +s_dist_06 char(24), +s_dist_07 char(24), +s_dist_08 char(24), +s_dist_09 char(24), +s_dist_10 char(24), +s_ytd decimal(8,0), +s_order_cnt smallint, +s_remote_cnt smallint, +s_data varchar(50), +PRIMARY KEY(s_w_id, s_i_id) ) Engine=InnoDB ; + +analyze customer; +analyze district; +analyze history; +analyze item; +analyze new_orders; +analyze order_line; +analyze orders; +analyze stock; +analyze warehouse; + +set enable_seqscan = off; +set dolphin.transform_unknown_param_type_as_column_type_first = true; + +prepare s1 as SELECT c_discount, c_last, c_credit, w_tax FROM customer, warehouse WHERE w_id = ? AND c_w_id = w_id AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + + +prepare s1 as SELECT d_next_o_id, d_tax FROM district WHERE d_id = ? AND d_w_id = ? FOR UPDATE; +explain (costs off) execute s1 using 1, 2; + + +prepare s1 as UPDATE district SET d_next_o_id = ? + 1 WHERE d_id = ? AND d_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) VALUES(?, ?, ?, ?, ?, ?, ?); +explain (costs off) execute s1 using 1, 2, 3, 4, '2024-10-10 10:10:10', 6, 7; + + +prepare s1 as INSERT INTO new_orders (no_o_id, no_d_id, no_w_id) VALUES (?,?,?); +explain (costs off) execute s1 using 1, 2, 3; + + +prepare s1 as SELECT i_price, i_name, i_data FROM item WHERE i_id = ?; +explain (costs off) execute s1 using 1; + +prepare s1 as SELECT s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 FROM stock WHERE s_i_id = ? AND s_w_id = ? FOR UPDATE; +explain (costs off) execute s1 using 1, 2; + +prepare s1 as UPDATE stock SET s_quantity = ? WHERE s_i_id = ? AND s_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as INSERT INTO order_line (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); +explain (costs off) execute s1 using 1, 2, 3, 4, 5, 6, 7, 8, 9; + +prepare s1 as UPDATE warehouse SET w_ytd = w_ytd + ? WHERE w_id = ?; +explain (costs off) execute s1 using 1, 2; + +prepare s1 as SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name FROM warehouse WHERE w_id = ?; +explain (costs off) execute s1 using 1; + +prepare s1 as UPDATE district SET d_ytd = d_ytd + ? WHERE d_w_id = ? AND d_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name FROM district WHERE d_w_id = ? AND d_id = ?; +explain (costs off) execute s1 using 1, 2; + +prepare s1 as SELECT count(c_id) FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT c_id FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? ORDER BY c_id; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_since FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ? FOR UPDATE; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT c_data FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as UPDATE customer SET c_balance = ?, c_data = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4, 5; + +prepare s1 as UPDATE customer SET c_balance = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4; + +prepare s1 as INSERT INTO history(h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES(?, ?, ?, ?, ?, ?, ?, ?); +explain (costs off) execute s1 using 1, 2, 3, 4, 5, '2024-10-10 10:10:10', 7, 8; + +prepare s1 as SELECT count(c_id) FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? ORDER BY c_first; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT c_balance, c_first, c_middle, c_last FROM customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0) FROM orders WHERE o_w_id = ? AND o_d_id = ? AND o_c_id = ? AND o_id = (SELECT MAX(o_id) FROM orders WHERE o_w_id = ? AND o_d_id = ? AND o_c_id = ?); +explain (costs off) execute s1 using 1, 2, 3, 4, 5, 6; + +prepare s1 as SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d FROM order_line WHERE ol_w_id = ? AND ol_d_id = ? AND ol_o_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT COALESCE(MIN(no_o_id),0) FROM new_orders WHERE no_d_id = ? AND no_w_id = ?; +explain (costs off) execute s1 using 1, 2; + +prepare s1 as DELETE FROM new_orders WHERE no_o_id = ? AND no_d_id = ? AND no_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as SELECT o_c_id FROM orders WHERE o_id = ? AND o_d_id = ? AND o_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as UPDATE orders SET o_carrier_id = ? WHERE o_id = ? AND o_d_id = ? AND o_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4; + +prepare s1 as UPDATE order_line SET ol_delivery_d = ? WHERE ol_o_id = ? AND ol_d_id = ? AND ol_w_id = ?; +explain (costs off) execute s1 using '2024-10-10 10:10:10', 2, 3, 4; + +prepare s1 as SELECT SUM(ol_amount) FROM order_line WHERE ol_o_id = ? AND ol_d_id = ? AND ol_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3; + +prepare s1 as UPDATE customer SET c_balance = c_balance + ? , c_delivery_cnt = c_delivery_cnt + 1 WHERE c_id = ? AND c_d_id = ? AND c_w_id = ?; +explain (costs off) execute s1 using 1, 2, 3, 4; + +prepare s1 as SELECT d_next_o_id FROM district WHERE d_id = ? AND d_w_id = ?; +explain (costs off) execute s1 using 1, 2; + +prepare s1 as SELECT DISTINCT ol_i_id FROM order_line WHERE ol_w_id = ? AND ol_d_id = ? AND ol_o_id < ? AND ol_o_id >= (? - 20); +explain (costs off) execute s1 using 1, 2, 3, 4; + +prepare s1 as SELECT count(*) FROM stock WHERE s_w_id = ? AND s_i_id = ? AND s_quantity < ?; +explain (costs off) execute s1 using 1, 2, 3; + + + +drop table customer; +drop table district; +drop table history; +drop table item; +drop table new_orders; +drop table order_line; +drop table orders; +drop table stock; +drop table warehouse; + +drop schema tpcc_plan cascade; +reset current_schema; + -- Gitee