lists.mariadb.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

commits

Thread Start a new thread
Threads by month
  • ----- 2025 -----
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
commits@lists.mariadb.org

  • 14603 discussions
[Commits] 595b916: MDEV-30218 Incorrect optimization for rowid_filtering
by IgorBabaev 31 Jan '23

31 Jan '23
revision-id: 595b916272e377bb00298e603abd9541dede9bf4 (mariadb-10.4.27-71-g595b916) parent(s): c8f2e9a5c0ac5905f28b050b7df5a9ffd914b7e7 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-31 00:10:41 -0800 message: MDEV-30218 Incorrect optimization for rowid_filtering Correction over ths last patch for this MDEV. --- mysql-test/main/join_nested_jcl6.result | 2 +- mysql-test/main/opt_trace.result | 13 +- .../main/opt_trace_index_merge_innodb.result | 1 - mysql-test/main/range.result | 2 +- mysql-test/main/rowid_filter.result | 189 ++++++++++++--------- mysql-test/main/rowid_filter_innodb.result | 102 ++++++++--- mysql-test/main/select.result | 2 +- mysql-test/main/select_jcl6.result | 2 +- mysql-test/main/select_pkeycache.result | 2 +- mysql-test/main/selectivity.result | 2 +- sql/sql_select.cc | 132 +++++++------- 11 files changed, 251 insertions(+), 198 deletions(-) diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result index 7226a5d..91fe367 100644 --- a/mysql-test/main/join_nested_jcl6.result +++ b/mysql-test/main/join_nested_jcl6.result @@ -2085,7 +2085,7 @@ ON t6.b >= 2 AND t5.b=t7.b AND (t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 -1 SIMPLE t7 ref PRIMARY,b_i b_i 5 test.t5.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter 1 SIMPLE t6 range PRIMARY,b_i PRIMARY 4 NULL 3 Using where; Rowid-ordered scan; Using join buffer (incremental, BNL join) 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 2eef0da..92cd3eb 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -1016,7 +1016,6 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 200, "chosen": true @@ -1073,7 +1072,6 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 200, "chosen": true @@ -2120,7 +2118,6 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "access_type": "ref", "index": "a_c", "used_range_estimates": true, - "rowid_filter_skipped": "worst/max seeks clipping", "rows": 180, "cost": 92, "chosen": true @@ -3346,7 +3343,6 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "access_type": "ref", "index": "pk", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 2, "chosen": true @@ -3355,7 +3351,6 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "access_type": "ref", "index": "pk_a", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 2, "chosen": false, @@ -3365,7 +3360,6 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "access_type": "ref", "index": "pk_a_b", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 1.0043, "chosen": true @@ -3974,6 +3968,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "best_access_path": { "considered_access_paths": [ { + "rowid_filter_skipped": "cost_factor <= 0", "access_type": "range", "resulting_rows": 3, "cost": 1.407, @@ -4000,7 +3995,6 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 3.007, "chosen": true @@ -4030,6 +4024,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "best_access_path": { "considered_access_paths": [ { + "rowid_filter_skipped": "cost_factor <= 0", "access_type": "range", "resulting_rows": 3, "cost": 1.407, @@ -4056,7 +4051,6 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", - "rowid_filter_skipped": "worst/max seeks clipping", "rows": 2, "cost": 3.014, "chosen": true @@ -8069,7 +8063,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "b", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 20, "chosen": true @@ -8273,7 +8266,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 20, "chosen": true @@ -8341,7 +8333,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 200, "chosen": true diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result index 82f09df..5786f74 100644 --- a/mysql-test/main/opt_trace_index_merge_innodb.result +++ b/mysql-test/main/opt_trace_index_merge_innodb.result @@ -208,7 +208,6 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "access_type": "ref", "index": "key1", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 2, "chosen": true diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index a3ce10f..0e728d7 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -281,7 +281,7 @@ INSERT INTO t1 VALUES (33,5),(33,5),(33,5),(33,5),(34,5),(35,5); EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 5 NULL 2 Using index condition; Using where +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 15 (5%) Using where; Using rowid filter SELECT * FROM t1 WHERE a IN(1,2) AND b=5; a b DROP TABLE t1; diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result index b35021b..efe1fe1 100644 --- a/mysql-test/main/rowid_filter.result +++ b/mysql-test/main/rowid_filter.result @@ -335,8 +335,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 Using index condition -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND @@ -346,40 +346,40 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "rows": 69, + "filtered": 100, + "index_condition": "orders.o_totalprice between 200000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "rows": 98, - "filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 69, - "selectivity_pct": 4.6 + "rows": 98, + "selectivity_pct": 1.632 }, - "rows": 1, - "filtered": 4.6, - "attached_condition": "orders.o_totalprice between 200000 and 230000" + "rows": 4, + "filtered": 1.632, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" } } } @@ -388,8 +388,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 98.00 100.00 100.00 Using index condition -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) 0.11 (10%) 4.60 100.00 Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 71.00 100.00 100.00 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) 0.15 (2%) 1.63 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND @@ -401,53 +401,53 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", - "possible_keys": [ - "PRIMARY", - "i_l_shipdate", - "i_l_orderkey", - "i_l_orderkey_quantity" - ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], "r_loops": 1, - "rows": 98, - "r_rows": 98, + "rows": 69, + "r_rows": 71, "r_total_time_ms": "REPLACED", "filtered": 100, "r_filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" + "index_condition": "orders.o_totalprice between 200000 and 230000" }, "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "table_name": "lineitem", + "access_type": "ref", + "possible_keys": [ + "PRIMARY", + "i_l_shipdate", + "i_l_orderkey", + "i_l_orderkey_quantity" + ], + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 69, - "selectivity_pct": 4.6, - "r_rows": 71, - "r_lookups": 96, - "r_selectivity_pct": 10.417, + "rows": 98, + "selectivity_pct": 1.632, + "r_rows": 98, + "r_lookups": 476, + "r_selectivity_pct": 2.3109, "r_buffer_size": "REPLACED", "r_filling_time_ms": "REPLACED" }, - "r_loops": 98, - "rows": 1, - "r_rows": 0.1122, + "r_loops": 71, + "rows": 4, + "r_rows": 0.1549, "r_total_time_ms": "REPLACED", - "filtered": 4.6, + "filtered": 1.632, "r_filtered": 100, - "attached_condition": "orders.o_totalprice between 200000 and 230000" + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" } } } @@ -2072,7 +2072,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 ref a1,b1 a1 5 test.t2.a2 36 28.75 Using where +1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2 @@ -2097,6 +2097,14 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a1"], "ref": ["test.t2.a2"], + "rowid_filter": { + "range": { + "key": "b1", + "used_key_parts": ["b1"] + }, + "rows": 115, + "selectivity_pct": 28.75 + }, "rows": 36, "filtered": 28.75, "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2" @@ -2179,7 +2187,7 @@ test.t1 analyze status OK explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a,b b 5 const 151 Using where +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 151 (17%) Using where; Using rowid filter SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2514,19 +2522,32 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 44, + "r_lookups": 1000, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, - "r_rows": 44, + "rows": 921, + "r_rows": 0, "r_total_time_ms": "REPLACED", - "filtered": 9.21, - "r_filtered": 0, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "filtered": 0.44, + "r_filtered": 100, + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } @@ -2559,19 +2580,31 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 0, + "r_lookups": 0, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, + "rows": 911, "r_rows": 0, - "r_total_time_ms": "REPLACED", - "filtered": 9.11, + "filtered": 0.44, "r_filtered": 100, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 1bf63d9..d7f1fe4 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -1997,7 +1997,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 ref a1,b1 a1 5 test.t2.a2 36 28.75 Using where +1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2 @@ -2022,6 +2022,14 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a1"], "ref": ["test.t2.a2"], + "rowid_filter": { + "range": { + "key": "b1", + "used_key_parts": ["b1"] + }, + "rows": 115, + "selectivity_pct": 28.75 + }, "rows": 36, "filtered": 28.75, "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2" @@ -2104,7 +2112,7 @@ test.t1 analyze status OK explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a,b b 5 const 128 Using where +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 128 (14%) Using where; Using rowid filter SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2439,19 +2447,32 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 44, + "r_lookups": 1000, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, - "r_rows": 44, + "rows": 921, + "r_rows": 0, "r_total_time_ms": "REPLACED", - "filtered": 9.21, - "r_filtered": 0, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "filtered": 0.44, + "r_filtered": 100, + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } @@ -2484,19 +2505,31 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 0, + "r_lookups": 0, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, + "rows": 911, "r_rows": 0, - "r_total_time_ms": "REPLACED", - "filtered": 9.11, + "filtered": 0.44, "r_filtered": 100, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } @@ -2671,7 +2704,7 @@ count(*) 5 explain extended select count(*) from t1 where a between 21 and 30 and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref b,a b 5 const 24 9.60 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 const 24 (10%) 9.60 Using where; Using rowid filter Warnings: Note 1003 select count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` between 21 and 30 select * from t1 where a between 21 and 30 and b=2; @@ -3133,7 +3166,7 @@ WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH) ORDER BY timestamp DESC; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainDomain 98 const 40 33.33 Using index condition; Using where; Using filesort +1 SIMPLE t1 ref|filter ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainDomain|ixEventWhoisDomainTimestamp 98|4 const 40 (33%) 33.33 Using index condition; Using where; Using filesort; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`domain` AS `domain`,`test`.`t1`.`registrant_name` AS `registrant_name`,`test`.`t1`.`registrant_organization` AS `registrant_organization`,`test`.`t1`.`registrant_street1` AS `registrant_street1`,`test`.`t1`.`registrant_street2` AS `registrant_street2`,`test`.`t1`.`registrant_street3` AS `registrant_street3`,`test`.`t1`.`registrant_street4` AS `registrant_street4`,`test`.`t1`.`registrant_street5` AS `registrant_street5`,`test`.`t1`.`registrant_city` AS `registrant_city`,`test`.`t1`.`registrant_postal_code` AS `registrant_postal_code`,`test`.`t1`.`registrant_country` AS `registrant_country`,`test`.`t1`.`registrant_email` AS `registrant_email`,`test`.`t1`.`registrant_telephone` AS `registrant_telephone`,`test`.`t1`.`administrative_name` AS `administrative_name`,`test`.`t1`.`administrative_organization` AS `administrative_organization`,`test`.`t1`.`administrative_street1` AS `administrative_street1`,`test`.`t1`.`administrative_stree t2` AS `administrative_street2`,`test`.`t1`.`administrative_street3` AS `administrative_street3`,`test`.`t1`.`administrative_street4` AS `administrative_street4`,`test`.`t1`.`administrative_street5` AS `administrative_street5`,`test`.`t1`.`administrative_city` AS `administrative_city`,`test`.`t1`.`administrative_postal_code` AS `administrative_postal_code`,`test`.`t1`.`administrative_country` AS `administrative_country`,`test`.`t1`.`administrative_email` AS `administrative_email`,`test`.`t1`.`administrative_telephone` AS `administrative_telephone`,`test`.`t1`.`technical_name` AS `technical_name`,`test`.`t1`.`technical_organization` AS `technical_organization`,`test`.`t1`.`technical_street1` AS `technical_street1`,`test`.`t1`.`technical_street2` AS `technical_street2`,`test`.`t1`.`technical_street3` AS `technical_street3`,`test`.`t1`.`technical_street4` AS `technical_street4`,`test`.`t1`.`technical_street5` AS `technical_street5`,`test`.`t1`.`technical_city` AS `technical_city`,`test `.`t1`.`technical_postal_code` AS `technical_postal_code`,`test`.`t1`.`technical_country` AS `technical_country`,`test`.`t1`.`technical_email` AS `technical_email`,`test`.`t1`.`technical_telephone` AS `technical_telephone`,`test`.`t1`.`json` AS `json`,`test`.`t1`.`timestamp` AS `timestamp` from `test`.`t1` where `test`.`t1`.`domain` = 'www.mailhost.i-dev.fr' and `test`.`t1`.`timestamp` >= <cache>('2017-01-30 08:24:51' + interval -1 month) order by `test`.`t1`.`timestamp` desc SET optimizer_switch=@save_optimizer_switch; @@ -3382,7 +3415,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where -1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where +1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using rowid filter Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -3498,7 +3531,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where; Using join buffer (flat, BKA join); Rowid-ordered scan -1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan +1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan; Using rowid filter Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -3616,9 +3649,22 @@ ANALYZE "key_length": "8", "used_key_parts": ["aceid"], "ref": ["test.a.id"], + "rowid_filter": { + "range": { + "key": "filt_fh", + "used_key_parts": ["fh"] + }, + "rows": 81, + "selectivity_pct": 14.464, + "r_rows": 80, + "r_lookups": 80, + "r_selectivity_pct": 40, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, "rows": 24, - "r_rows": 80, + "r_rows": 32, "r_total_time_ms": "REPLACED", "filtered": 14.464, "r_filtered": 100 @@ -3628,7 +3674,7 @@ ANALYZE "join_type": "BKA", "mrr_type": "Rowid-ordered scan", "attached_condition": "fi.fh in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)", - "r_filtered": 40 + "r_filtered": 100 } } } @@ -3732,7 +3778,7 @@ WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1 WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 60 100.00 Using where -2 DEPENDENT SUBQUERY t2 ref c1,i1 i1 5 test.t1.pk 20 100.00 Using index condition; Using where +2 DEPENDENT SUBQUERY t2 ref|filter c1,i1 c1|i1 3|5 func 38 (25%) 25.00 Using where; Full scan on NULL key; Using rowid filter 2 DEPENDENT SUBQUERY a1 ALL NULL NULL NULL NULL 60 100.00 Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 diff --git a/mysql-test/main/select.result b/mysql-test/main/select.result index fc3a290..6652b1a 100644 --- a/mysql-test/main/select.result +++ b/mysql-test/main/select.result @@ -3744,7 +3744,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); diff --git a/mysql-test/main/select_jcl6.result b/mysql-test/main/select_jcl6.result index e7c2e3e..cef6e0f 100644 --- a/mysql-test/main/select_jcl6.result +++ b/mysql-test/main/select_jcl6.result @@ -3755,7 +3755,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); diff --git a/mysql-test/main/select_pkeycache.result b/mysql-test/main/select_pkeycache.result index fc3a290..6652b1a 100644 --- a/mysql-test/main/select_pkeycache.result +++ b/mysql-test/main/select_pkeycache.result @@ -3744,7 +3744,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result index 4113779..7e32023 100644 --- a/mysql-test/main/selectivity.result +++ b/mysql-test/main/selectivity.result @@ -1661,7 +1661,7 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` # gives selectivity data explain extended select * from t1 where a in (17,51,5) and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref b,a b 5 const 58 2.90 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 const 58 (3%) 2.90 Using where; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5) drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0f8ead4..350d43f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7557,7 +7557,6 @@ best_access_path(JOIN *join, rec= MATCHING_ROWS_IN_OTHER_TABLE; // Fix for small tables Json_writer_object trace_access_idx(thd); - double eq_ref_rows= 0; /* full text keys require special treatment */ @@ -7596,8 +7595,7 @@ best_access_path(JOIN *join, type= JT_EQ_REF; trace_access_idx.add("access_type", join_type_str[type]) .add("index", keyinfo->name); - eq_ref_rows= tmp = prev_record_reads(join_positions, idx, - found_ref); + tmp = prev_record_reads(join_positions, idx, found_ref); records=1.0; } else @@ -7904,28 +7902,7 @@ best_access_path(JOIN *join, (s->table->file->index_flags(start_key->key,0,1) & HA_DO_RANGE_FILTER_PUSHDOWN)) { - double rows; - if (type == JT_EQ_REF) - { - /* - Treat EQ_REF access in a special way: - 1. We have no cost for index-only read. Assume its cost is 50% of - the cost of the full read. - - 2. A regular ref access will do #record_count lookups, but eq_ref - has "lookup cache" which reduces the number of lookups made. - The estimation code uses prev_record_reads() call to estimate: - - tmp = prev_record_reads(join_positions, idx, found_ref); - - Set the effective number of rows from "tmp" here. - */ - keyread_tmp= COST_ADD(eq_ref_rows / 2, s->startup_cost); - rows= eq_ref_rows; - } - else - rows= record_count * records; - + double rows= record_count * records; /* If we use filter F with selectivity s the the cost of fetching data by key using this filter will be @@ -7947,46 +7924,53 @@ best_access_path(JOIN *join, cost_of_fetching_1_row = tmp/rows cost_of_fetching_1_key_tuple = keyread_tmp/rows - access_cost_factor is the gain we expect for using rowid filter. - An access_cost_factor of 1.0 means that keyread_tmp is 0 - (using key read is infinitely fast) and the gain for each row when - using filter is great. - An access_cost_factor if 0.0 means that using keyread has the - same cost as reading rows, so there is no gain to get with - filter. - access_cost_factor should never be bigger than 1.0 (if all - calculations are correct) as the cost of keyread should always be - smaller than the cost of fetching the same number of keys + rows. - access_cost_factor should also never be smaller than 0.0. - The one exception is if number of records is 1 (eq_ref), then - because we are comparing rows to cost of keyread_tmp, keyread_tmp - is higher by 1.0. This is a big that will be fixed in a later - version. - - If we have limited the cost (=tmp) of reading rows with 'worst_seek' - we cannot use filters as the cost calculation below would cause - tmp to become negative. The future resultion is to not limit - cost with worst_seek. + Here's a more detailed explanation that uses the formulas behind + the function the call filter->get_adjusted_gain(). The function + takes as a parameter the number of probes/look-ups into the filter + that is equal to the number of fetched key entries that is equal to + the number of row fetches when no filter is used (assuming no + index condition pushdown is employed for the used key access). + Let this number be N. Then the total gain from using the filter is + N*a_adj - b where b is the cost of building the filter and + a_adj is calcilated as follows: + a - (1-access_cost_factor)*(1-s) = + (1+1_cond_eval_cost)*(1-s)-1_probe_cost - (1-access_cost_factor)*(1-s) + = (1-s)*(1_cond_eval_cost+access_cost_factor) - 1_probe_cost. + Here ((1-s)*(1_cond_eval_cost) * N is the gain from checking less + conditions pushed into the table, 1_probe_cost*N is the cost of the + probes and (1*s) * access_cost_factor * N must be the gain from + accessing less rows. + It does not matter how we calculate the cost of N full row fetches + cost_of_fetching_N_rows or + how we calculate the cost of fetching N key entries + cost_of_fetching_N_key_entries + the gain from less row fetches will be + (cost_of_fetching_N_rows - cost_of_fetching_N_key_entries) * (1-s) + and this should be equal to (1*s) * access_cost_factor * N. + Thus access_cost_factor must be calculated as + (cost_of_fetching_N_rows - cost_of_fetching_N_key_entries) / N. + + For safety we clip cost_of_fetching_N_key_entries by the value + of cost_of_fethching_N_row though formally it's not necessary. */ - double access_cost_factor= MY_MIN((rows - keyread_tmp) / rows, 1.0); - if (!(records < s->worst_seeks && - records <= thd->variables.max_seeks_for_key)) - trace_access_idx.add("rowid_filter_skipped", "worst/max seeks clipping"); - else if (access_cost_factor <= 0.0) - trace_access_idx.add("rowid_filter_skipped", "cost_factor <= 0"); - else + /* + For eq_ref access we assume that the cost of fetching N key entries + is equal to the half of fetching N rows + */ + double key_access_cost= + type == JT_EQ_REF ? 0.5 * tmp : MY_MIN(tmp, keyread_tmp); + double access_cost_factor= MY_MIN((tmp - key_access_cost) / rows, 1.0); + + filter= + table->best_range_rowid_filter_for_partial_join(start_key->key, + rows, + access_cost_factor); + if (filter) { - filter= - table->best_range_rowid_filter_for_partial_join(start_key->key, - rows, - access_cost_factor); - if (filter) - { - tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows); - DBUG_ASSERT(tmp >= 0); - trace_access_idx.add("rowid_filter_key", + tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows); + DBUG_ASSERT(tmp >= 0); + trace_access_idx.add("rowid_filter_key", s->table->key_info[filter->key_no].name); - } } } trace_access_idx.add("rows", records).add("cost", tmp); @@ -8139,19 +8123,19 @@ best_access_path(JOIN *join, uint key_no= s->quick->index; /* See the comment concerning using rowid filter for with ref access */ - keyread_tmp= s->table->quick_index_only_costs[key_no] * record_count; - double access_cost_factor= MY_MIN((rows - keyread_tmp) / rows, 1.0); - if (access_cost_factor > 0.0) + double row_access_cost= s->quick->read_time * record_count; + double key_access_cost= + MY_MIN(row_access_cost, + s->table->quick_index_only_costs[key_no] * record_count); + double access_cost_factor= MY_MIN((row_access_cost - key_access_cost) / + rows, 1.0); + filter= + s->table->best_range_rowid_filter_for_partial_join(key_no, rows, + access_cost_factor); + if (filter) { - filter= - s->table-> - best_range_rowid_filter_for_partial_join(key_no, rows, - access_cost_factor); - if (filter) - { - tmp-= filter->get_adjusted_gain(rows); - DBUG_ASSERT(tmp >= 0); - } + tmp-= filter->get_adjusted_gain(rows); + DBUG_ASSERT(tmp >= 0); } else trace_access_scan.add("rowid_filter_skipped", "cost_factor <= 0");
1 0
0 0
[Commits] 98922da: Merge branch 'bb-10.4-release' of github.com:MariaDB/server into bb-10.4-release
by IgorBabaev 31 Jan '23

31 Jan '23
revision-id: 98922dabb74bb05cd97003e4a0c5f3b2a878ccf0 (mariadb-10.4.27-70-g98922da) parent(s): c8f9bb2718c4ed7b464504c54df961bfeb2cccca c8f2e9a5c0ac5905f28b050b7df5a9ffd914b7e7 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-30 21:02:35 -0800 message: Merge branch 'bb-10.4-release' of github.com:MariaDB/server into bb-10.4-release # Conflicts: # sql/sql_select.cc .../r/binlog_recovery_after_checksum_change.result | 8 ---- .../binlog/r/innodb_rc_insert_before_delete.result | 52 ++++++++++++++++++++++ sql/sql_select.cc | 8 ++-- 3 files changed, 57 insertions(+), 11 deletions(-)
1 0
0 0
[Commits] b6e958e: MDEV-28958 Crash when checking whether condition can be pushed into view
by IgorBabaev 31 Jan '23

31 Jan '23
revision-id: b6e958edc5fb147fcfeb4a3837d14daacfa2c93e (mariadb-10.7.4-105-gb6e958e) parent(s): cea50896d2ea0d18924d92d62a7ec1607d55e509 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-30 19:42:27 -0800 message: MDEV-28958 Crash when checking whether condition can be pushed into view Do not set any flags in the items for constant subformulas TRUE/FALSE when checking pushability of a formula into a view. Occurrences of these subformulas can be ignored when checking pushability of the formula. At the same time the items used for these constants became immutable starting from version 10.7. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/derived_cond_pushdown.result | 17 +++++++++++++++++ mysql-test/main/derived_cond_pushdown.test | 21 +++++++++++++++++++++ sql/item.h | 23 ++++++++++++++++------- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 5b0cc4a..b1fefd2 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -18186,3 +18186,20 @@ id select_type table type possible_keys key key_len ref rows Extra drop view v1; drop table t1; # End of 10.4 tests +# +# MDEV-28958: condition pushable into view after simplification +# contains constant TRUE/FALSE as subformula +# +create table t1 (c1 int); +insert into t1 values (3), (7), (1), (3), (1), (3); +create table t2 (c2 int); +insert into t2 values (3), (5), (7), (3); +create view v1 as select * from t1 group by c1; +create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2; +select * from v2 group by a,b having a=b or b > a+10; +a b +3 3 +7 7 +drop view v1,v2; +drop table t1,t2; +# End of 10.7 tests diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 39e8221..8fdc54d 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -3895,3 +3895,24 @@ drop view v1; drop table t1; --echo # End of 10.4 tests + +--echo # +--echo # MDEV-28958: condition pushable into view after simplification +--echo # contains constant TRUE/FALSE as subformula +--echo # + +create table t1 (c1 int); +insert into t1 values (3), (7), (1), (3), (1), (3); + +create table t2 (c2 int); +insert into t2 values (3), (5), (7), (3); + +create view v1 as select * from t1 group by c1; +create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2; + +select * from v2 group by a,b having a=b or b > a+10; + +drop view v1,v2; +drop table t1,t2; + +--echo # End of 10.7 tests diff --git a/sql/item.h b/sql/item.h index d197ebb..59d395a 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2681,18 +2681,27 @@ class Item :public Value_source, void register_in(THD *thd); bool depends_only_on(table_map view_map) - { return marker & MARKER_FULL_EXTRACTION; } - int get_extraction_flag() const - { return marker & MARKER_EXTRACTION_MASK; } + { return get_extraction_flag() & MARKER_FULL_EXTRACTION; } + int get_extraction_flag() const + { + if (basic_const_item()) + return MARKER_FULL_EXTRACTION; + else + return marker & MARKER_EXTRACTION_MASK; + } void set_extraction_flag(int16 flags) { - marker &= ~MARKER_EXTRACTION_MASK; - marker|= flags; + if (!basic_const_item()) + { + marker= marker & ~MARKER_EXTRACTION_MASK; + marker|= flags; + } } void clear_extraction_flag() { - marker &= ~MARKER_EXTRACTION_MASK; - } + if (!basic_const_item()) + marker= marker & ~MARKER_EXTRACTION_MASK; + } void check_pushable_cond(Pushdown_checker excl_dep_func, uchar *arg); bool pushable_cond_checker_for_derived(uchar *arg) {
1 0
0 0
[Commits] 2530783: MDEV-28616 Crash when using derived table over union with order by clause
by IgorBabaev 25 Jan '23

25 Jan '23
revision-id: 253078337ca6019badfaf359d9302c8a479746ca (mariadb-10.3.35-379-g2530783) parent(s): f513d715382a63415c9342f1cae75be75b441f98 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-25 11:46:28 -0800 message: MDEV-28616 Crash when using derived table over union with order by clause This bug manifested itself when the server processed a query containing a derived table over union whose ORDER BY clause included a subquery with unresolvable column reference. For such a query the server crashed when trying to resolve column references in the ORDER BY clause used by union. For any union with ORDER BY clause an extra SELECT_LEX structure is created and it is attached to SELECT_LEX_UNIT structure of the union via the field fake_select_lex. The outer context for fake_select_lex must be the same as for other selects of the union. If the union is used in the FROM list of a derived table then the outer context for fake_select_lex must be set to NULL in line with other selects of the union. It was not done and it caused a crash when searching for possible resolution of an unresolvable column reference occurred in a subquery used in the ORDER BY clause. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/derived.result | 23 +++++++++++++++++++++++ mysql-test/main/derived.test | 30 ++++++++++++++++++++++++++++++ sql/sql_derived.cc | 3 +++ 3 files changed, 56 insertions(+) diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result index 2761fdf..0cb029f 100644 --- a/mysql-test/main/derived.result +++ b/mysql-test/main/derived.result @@ -1327,5 +1327,28 @@ a b DROP VIEW v1; DROP TABLE t1; # +# MDEV-28616: derived table over union with order by clause that +# contains subquery with unresolvable column reference +# +SELECT 1 FROM ( +SELECT 1 UNION SELECT 2 ORDER BY (SELECT 1 FROM DUAL WHERE xxx = 0) +) dt; +ERROR 42S22: Unknown column 'xxx' in 'where clause' +create table t1 (a int, b int); +insert into t1 values (3,8), (7,2), (1,4), (5,9); +create table t2 (a int, b int); +insert into t2 values (9,1), (7,3), (2,6); +create table t3 (c int, d int); +insert into t3 values (7,8), (1,2), (3,8); +select * from +( +select a,b from t1 where t1.a > 3 +union +select a,b from t2 where t2.b < 6 +order by (a - b / (select a + max(c) from t3 where d = x)) +) dt; +ERROR 42S22: Unknown column 'x' in 'where clause' +drop table t1,t2,t3; +# # End of 10.3 tests # diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test index 6a83100..dca7243 100644 --- a/mysql-test/main/derived.test +++ b/mysql-test/main/derived.test @@ -1138,5 +1138,35 @@ DROP VIEW v1; DROP TABLE t1; --echo # +--echo # MDEV-28616: derived table over union with order by clause that +--echo # contains subquery with unresolvable column reference +--echo # + +--error ER_BAD_FIELD_ERROR +SELECT 1 FROM ( + SELECT 1 UNION SELECT 2 ORDER BY (SELECT 1 FROM DUAL WHERE xxx = 0) +) dt; + +create table t1 (a int, b int); +insert into t1 values (3,8), (7,2), (1,4), (5,9); + +create table t2 (a int, b int); +insert into t2 values (9,1), (7,3), (2,6); + +create table t3 (c int, d int); +insert into t3 values (7,8), (1,2), (3,8); + +--error ER_BAD_FIELD_ERROR +select * from +( + select a,b from t1 where t1.a > 3 + union + select a,b from t2 where t2.b < 6 + order by (a - b / (select a + max(c) from t3 where d = x)) +) dt; + +drop table t1,t2,t3; + +--echo # --echo # End of 10.3 tests --echo # diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 93dc628..8177ee2 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -771,6 +771,9 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) cursor->outer_join|= JOIN_TYPE_OUTER; } } + // Prevent it for possible ORDER BY clause + if (unit->fake_select_lex) + unit->fake_select_lex->context.outer_context= 0; /* Above cascade call of prepare is important for PS protocol, but after it
1 0
0 0
[Commits] db2eeaf: MDEV-30081 Crash with splitting from constant mergeable derived table
by IgorBabaev 23 Jan '23

23 Jan '23
revision-id: db2eeafc20de584d430ce9c0903478aeb8782d66 (mariadb-10.3.35-375-gdb2eeaf) parent(s): 074bef4dcaad15dba40013e9d2ddf0011b7744a1 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-23 15:54:49 -0800 message: MDEV-30081 Crash with splitting from constant mergeable derived table This bug manifested itself in very rare situations when splitting optimization was applied to a materialized derived table with group clause by key over a constant meargeable derived table that was in inner part of an outer join. In this case the used tables for the key to access the split table incorrectly was evaluated to a not empty table map. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/derived_cond_pushdown.result | 58 ++++++++++++++++++++++++++++ mysql-test/main/derived_cond_pushdown.test | 49 +++++++++++++++++++++++ sql/item.cc | 2 +- 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index ebe0c229..88f20bc 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -18131,4 +18131,62 @@ DROP TABLE transaction_items; DROP TABLE transactions; DROP TABLE charges; DROP TABLE ledgers; +# +# MDEV-30081: Splitting from a constant mergeable derived table +# used in inner part of an outer join. +# +CREATE TABLE t1 ( id int PRIMARY KEY ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (3),(4),(7); +CREATE TABLE t2 ( +id int, id1 int, wid int, PRIMARY KEY (id), KEY (id1), KEY (wid) +) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4,4,6),(7,7,7); +CREATE TABLE t3 ( +wid int, wtid int, otid int, oid int, +PRIMARY KEY (wid), KEY (wtid), KEY (otid), KEY (oid) +) ENGINE=MyISAM; +INSERT INTO t3 VALUES (6,30,6,6),(7,17,7,7); +CREATE TABLE t4 ( id int, a int, PRIMARY KEY (id), KEY (a) ) ENGINE=MyISAM; +INSERT INTO t4 VALUES (1,17),(2,15),(3,49),(4,3),(5,45),(6,38),(7,17); +CREATE TABLE t5 ( +id int, id1 int, PRIMARY KEY (id), KEY id1 (id1) +) ENGINE=MyISAM ; +INSERT INTO t5 VALUES (1,17),(2,15),(3,49),(4,3),(5,45),(6,38),(7,17); +ANALYZE TABLE t1,t2,t3,t4,t5; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +test.t4 analyze status OK +test.t5 analyze status OK +CREATE VIEW v1 AS (SELECT id1 FROM t5 GROUP BY id1); +SELECT t3.*, t1.id AS t1_id, t2.id AS t2_id, dt.*, v1.* +FROM +t1, t2, t3 +LEFT JOIN +(SELECT t4.* FROM t4 WHERE t4.a=3) dt +ON t3.oid = dt.id AND t3.otid = 14 +LEFT JOIN v1 +ON (v1.id1 = dt.a) +WHERE t3.oid = t1.id AND t3.oid = t2.id AND t3.wid = 7; +wid wtid otid oid t1_id t2_id id a id1 +7 17 7 7 7 7 NULL NULL NULL +EXPLAIN SELECT t3.*, t1.id AS t1_id, t2.id AS t2_id, dt.*, v1.* +FROM +t1, t2, t3 +LEFT JOIN +(SELECT t4.* FROM t4 WHERE t4.a=3) dt +ON t3.oid = dt.id AND t3.otid = 14 +LEFT JOIN v1 +ON (v1.id1 = dt.a) +WHERE t3.oid = t1.id AND t3.oid = t2.id AND t3.wid = 7; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t3 const PRIMARY,oid PRIMARY 4 const 1 +1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY t2 const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY t4 const PRIMARY,a NULL NULL NULL 1 Impossible ON condition +1 PRIMARY <derived3> ref key0 key0 5 const 0 Using where +3 LATERAL DERIVED t5 ref id1 id1 5 const 0 Using index +DROP VIEW v1; +DROP TABLE t1,t2,t3,t4,t5; # End of 10.3 tests diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 619d104..e039d1f 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -3853,4 +3853,53 @@ DROP TABLE transactions; DROP TABLE charges; DROP TABLE ledgers; + +--echo # +--echo # MDEV-30081: Splitting from a constant mergeable derived table +--echo # used in inner part of an outer join. +--echo # + + CREATE TABLE t1 ( id int PRIMARY KEY ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (3),(4),(7); + +CREATE TABLE t2 ( + id int, id1 int, wid int, PRIMARY KEY (id), KEY (id1), KEY (wid) +) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4,4,6),(7,7,7); + +CREATE TABLE t3 ( + wid int, wtid int, otid int, oid int, + PRIMARY KEY (wid), KEY (wtid), KEY (otid), KEY (oid) +) ENGINE=MyISAM; +INSERT INTO t3 VALUES (6,30,6,6),(7,17,7,7); + +CREATE TABLE t4 ( id int, a int, PRIMARY KEY (id), KEY (a) ) ENGINE=MyISAM; +INSERT INTO t4 VALUES (1,17),(2,15),(3,49),(4,3),(5,45),(6,38),(7,17); + +CREATE TABLE t5 ( + id int, id1 int, PRIMARY KEY (id), KEY id1 (id1) +) ENGINE=MyISAM ; +INSERT INTO t5 VALUES (1,17),(2,15),(3,49),(4,3),(5,45),(6,38),(7,17); + +ANALYZE TABLE t1,t2,t3,t4,t5; + +CREATE VIEW v1 AS (SELECT id1 FROM t5 GROUP BY id1); + +let $q= +SELECT t3.*, t1.id AS t1_id, t2.id AS t2_id, dt.*, v1.* +FROM + t1, t2, t3 + LEFT JOIN + (SELECT t4.* FROM t4 WHERE t4.a=3) dt + ON t3.oid = dt.id AND t3.otid = 14 + LEFT JOIN v1 + ON (v1.id1 = dt.a) +WHERE t3.oid = t1.id AND t3.oid = t2.id AND t3.wid = 7; + +eval $q; +eval EXPLAIN $q; + +DROP VIEW v1; +DROP TABLE t1,t2,t3,t4,t5; + --echo # End of 10.3 tests diff --git a/sql/item.cc b/sql/item.cc index 02220fd..9ecbefa 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -10838,7 +10838,7 @@ table_map Item_direct_view_ref::used_tables() const table_map used= (*ref)->used_tables(); return (used ? used : - ((null_ref_table != NO_NULL_TABLE) ? + (null_ref_table != NO_NULL_TABLE && !null_ref_table->const_table ? null_ref_table->map : (table_map)0 )); }
1 0
0 0
[Commits] f592bd2: MDEV-30248 Infinite sequence of recursive calls when processing embedded CTE
by IgorBabaev 21 Jan '23

21 Jan '23
revision-id: f592bd26817dd5cc87d7a045526e60daab4492d1 (mariadb-10.3.35-367-gf592bd2) parent(s): 489b556947087f7606224d6fc09f302eabef14c8 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-21 00:09:58 -0800 message: MDEV-30248 Infinite sequence of recursive calls when processing embedded CTE This patch fixes the patch for bug MDEV-30248 that unsatisfactorily resolved the problem of resolution of references to CTE. In some cases when such a reference has the same table name as the name of one of CTEs containing this reference the reference could be resolved incorrectly that led to an invalid select tree where units could be mutually dependent. This in its turn could lead to an infinite sequence of recursive calls or to falls into infinite loops. The patch also removes LEX::resolve_references_to_cte_in_hanging_cte() as with the new code for resolution of CTE references the call of this function is not needed anymore. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/cte_recursive.result | 172 +++++++++++++++++++++++++++++++++++ mysql-test/main/cte_recursive.test | 123 +++++++++++++++++++++++++ sql/sql_cte.cc | 91 ++++-------------- sql/sql_cte.h | 5 - sql/sql_lex.h | 1 - 5 files changed, 311 insertions(+), 81 deletions(-) diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result index c4b6679..e7aeeff 100644 --- a/mysql-test/main/cte_recursive.result +++ b/mysql-test/main/cte_recursive.result @@ -5604,5 +5604,177 @@ r 3 drop table t1,t2,t3,x; # +# MDEV-30248: Embedded non-recursive CTE referring to base table 'x' +# within a CTE with name 'x' used in a subquery from +# select list of another CTE +# +CREATE TABLE x (a int) ENGINE=MyISAM; +INSERT INTO x VALUES (3),(7),(1); +CREATE TABLE t1 (b int) ENGINE=MYISAM; +INSERT INTO t1 VALUES (1); +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT 1 AS b) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +c +1 +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT b FROM t1) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +c +1 +WITH cte AS +( +SELECT +( +WITH x AS +(WITH y AS (SELECT a FROM x AS t) SELECT b FROM t1) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +c +1 +WITH cte AS +( +SELECT +( +WITH x AS +(WITH y(b) AS (SELECT a FROM x AS t LIMIT 1) SELECT b FROM y) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +c +3 +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x(b) AS (SELECT a FROM x AS t LIMIT 1) SELECT b FROM x) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +c +3 +WITH x AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT 1 AS b) +SELECT b FROM x AS r +) AS c +) +SELECT x.c from x; +c +1 +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT 2 AS b) +SELECT r1.b FROM x AS r1, x AS r2 WHERE r1.b=r2.b +) AS c +) +SELECT cte.c from cte; +c +2 +DROP TABLE x; +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT 1 AS b) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +ERROR 42S02: Table 'test.x' doesn't exist +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT b FROM t1) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +ERROR 42S02: Table 'test.x' doesn't exist +WITH cte AS +( +SELECT +( +WITH x AS +(WITH y AS (SELECT a FROM x AS t) SELECT b FROM t1) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +ERROR 42S02: Table 'test.x' doesn't exist +WITH cte AS +( +SELECT +( +WITH x AS +(WITH y(b) AS (SELECT a FROM x AS t LIMIT 1) SELECT b FROM y) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +ERROR 42S02: Table 'test.x' doesn't exist +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x(b) AS (SELECT a FROM x AS t LIMIT 1) SELECT b FROM x) +SELECT b FROM x AS r +) AS c +) +SELECT cte.c FROM cte; +ERROR 42S02: Table 'test.x' doesn't exist +WITH x AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT 1 AS b) +SELECT b FROM x AS r +) AS c +) +SELECT x.c from x; +ERROR 42S02: Table 'test.x' doesn't exist +WITH cte AS +( +SELECT +( +WITH x AS +(WITH x AS (SELECT a FROM x AS t) SELECT 2 AS b) +SELECT r1.b FROM x AS r1, x AS r2 WHERE r1.b=r2.b +) AS c +) +SELECT cte.c from cte; +ERROR 42S02: Table 'test.x' doesn't exist +DROP TABLE t1; +# # End of 10.3 tests # diff --git a/mysql-test/main/cte_recursive.test b/mysql-test/main/cte_recursive.test index 270a502..f4dafbf 100644 --- a/mysql-test/main/cte_recursive.test +++ b/mysql-test/main/cte_recursive.test @@ -3872,5 +3872,128 @@ select * from cte; drop table t1,t2,t3,x; --echo # +--echo # MDEV-30248: Embedded non-recursive CTE referring to base table 'x' +--echo # within a CTE with name 'x' used in a subquery from +--echo # select list of another CTE +--echo # + +CREATE TABLE x (a int) ENGINE=MyISAM; +INSERT INTO x VALUES (3),(7),(1); +CREATE TABLE t1 (b int) ENGINE=MYISAM; +INSERT INTO t1 VALUES (1); + +let $q1= +WITH cte AS +( + SELECT + ( + WITH x AS + (WITH x AS (SELECT a FROM x AS t) SELECT 1 AS b) + SELECT b FROM x AS r + ) AS c +) +SELECT cte.c FROM cte; +eval $q1; + +let $q2= +WITH cte AS +( + SELECT + ( + WITH x AS + (WITH x AS (SELECT a FROM x AS t) SELECT b FROM t1) + SELECT b FROM x AS r + ) AS c +) +SELECT cte.c FROM cte; +eval $q2; + +let $q3= +WITH cte AS +( + SELECT + ( + WITH x AS + (WITH y AS (SELECT a FROM x AS t) SELECT b FROM t1) + SELECT b FROM x AS r + ) AS c +) +SELECT cte.c FROM cte; +eval $q3; + + +let $q4= +WITH cte AS +( + SELECT + ( + WITH x AS + (WITH y(b) AS (SELECT a FROM x AS t LIMIT 1) SELECT b FROM y) + SELECT b FROM x AS r + ) AS c +) +SELECT cte.c FROM cte; +eval $q4; + +let $q5= +WITH cte AS +( + SELECT + ( + WITH x AS + (WITH x(b) AS (SELECT a FROM x AS t LIMIT 1) SELECT b FROM x) + SELECT b FROM x AS r + ) AS c +) +SELECT cte.c FROM cte; +eval $q5; + +let $q6= +WITH x AS +( + SELECT + ( + WITH x AS + (WITH x AS (SELECT a FROM x AS t) SELECT 1 AS b) + SELECT b FROM x AS r + ) AS c +) +SELECT x.c from x; +eval $q6; + +let $q7= +WITH cte AS +( + SELECT + ( + WITH x AS + (WITH x AS (SELECT a FROM x AS t) SELECT 2 AS b) + SELECT r1.b FROM x AS r1, x AS r2 WHERE r1.b=r2.b + ) AS c +) +SELECT cte.c from cte; +eval $q7; + + +DROP TABLE x; + +--ERROR ER_NO_SUCH_TABLE +eval $q1; +--ERROR ER_NO_SUCH_TABLE +eval $q2; +--ERROR ER_NO_SUCH_TABLE +eval $q3; +--ERROR ER_NO_SUCH_TABLE +eval $q4; +--ERROR ER_NO_SUCH_TABLE +eval $q5; +--ERROR ER_NO_SUCH_TABLE +eval $q6; +--ERROR ER_NO_SUCH_TABLE +eval $q7; + +DROP TABLE t1; + +--echo # --echo # End of 10.3 tests --echo # diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index d7e3eec..b3b54d7 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -93,49 +93,6 @@ bool LEX::check_dependencies_in_with_clauses() /** @brief - Resolve references to CTE in specification of hanging CTE - - @details - A CTE to which there are no references in the query is called hanging CTE. - Although such CTE is not used for execution its specification must be - subject to context analysis. All errors concerning references to - non-existing tables or fields occurred in the specification must be - reported as well as all other errors caught at the prepare stage. - The specification of a hanging CTE might contain references to other - CTE outside of the specification and within it if the specification - contains a with clause. This function resolves all such references for - all hanging CTEs encountered in the processed query. - - @retval - false on success - true on failure -*/ - -bool -LEX::resolve_references_to_cte_in_hanging_cte() -{ - for (With_clause *with_clause= with_clauses_list; - with_clause; with_clause= with_clause->next_with_clause) - { - for (With_element *with_elem= with_clause->with_list.first; - with_elem; with_elem= with_elem->next) - { - if (!with_elem->is_referenced()) - { - TABLE_LIST *first_tbl= - with_elem->spec->first_select()->table_list.first; - TABLE_LIST **with_elem_end_pos= with_elem->head->tables_pos.end_pos; - if (first_tbl && resolve_references_to_cte(first_tbl, with_elem_end_pos)) - return true; - } - } - } - return false; -} - - -/** - @brief Resolve table references to CTE from a sub-chain of table references @param tables Points to the beginning of the sub-chain @@ -279,8 +236,6 @@ LEX::check_cte_dependencies_and_resolve_references() return false; if (resolve_references_to_cte(query_tables, query_tables_last)) return true; - if (resolve_references_to_cte_in_hanging_cte()) - return true; return false; } @@ -479,47 +434,33 @@ With_element *find_table_def_in_with_clauses(TABLE_LIST *tbl, st_unit_ctxt_elem *ctxt) { With_element *found= 0; + st_select_lex_unit *top_unit= 0; for (st_unit_ctxt_elem *unit_ctxt_elem= ctxt; unit_ctxt_elem; unit_ctxt_elem= unit_ctxt_elem->prev) { st_select_lex_unit *unit= unit_ctxt_elem->unit; With_clause *with_clause= unit->with_clause; - /* - First look for the table definition in the with clause attached to 'unit' - if there is any such clause. - */ if (with_clause) { - found= with_clause->find_table_def(tbl, NULL); + /* + If the reference to tbl that has to be resolved belongs to + the FROM clause of a descendant of top_unit->with_element + and this with element belongs to with_clause then this + element must be used as the barrier for the search in the + the list of CTEs from with_clause unless the clause contains + RECURSIVE. + */ + With_element *barrier= 0; + if (top_unit && !with_clause->with_recursive && + top_unit->with_element && + top_unit->with_element->get_owner() == with_clause) + barrier= top_unit->with_element; + found= with_clause->find_table_def(tbl, barrier); if (found) break; } - /* - If 'unit' is the unit that defines a with element then reset 'unit' - to the unit whose attached with clause contains this with element. - */ - With_element *with_elem= unit->with_element; - if (with_elem) - { - if (!(unit_ctxt_elem= unit_ctxt_elem->prev)) - break; - unit= unit_ctxt_elem->unit; - } - with_clause= unit->with_clause; - /* - Now look for the table definition in this with clause. If the with clause - contains RECURSIVE the search is performed through all CTE definitions in - clause, otherwise up to the definition of 'with_elem' unless it is NULL. - */ - if (with_clause) - { - found= with_clause->find_table_def(tbl, - with_clause->with_recursive ? - NULL : with_elem); - if (found) - break; - } + top_unit= unit; } return found; } diff --git a/sql/sql_cte.h b/sql/sql_cte.h index b270818..d9dda3e 100644 --- a/sql/sql_cte.h +++ b/sql/sql_cte.h @@ -322,8 +322,6 @@ class With_element : public Sql_alloc friend bool LEX::resolve_references_to_cte(TABLE_LIST *tables, TABLE_LIST **tables_last); - friend - bool LEX::resolve_references_to_cte_in_hanging_cte(); }; const uint max_number_of_elements_in_with_clause= sizeof(table_map)*8; @@ -435,9 +433,6 @@ class With_clause : public Sql_alloc friend bool LEX::check_dependencies_in_with_clauses(); - - friend - bool LEX::resolve_references_to_cte_in_hanging_cte(); }; inline diff --git a/sql/sql_lex.h b/sql/sql_lex.h index bdc8b54..d594b8d 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -4053,7 +4053,6 @@ struct LEX: public Query_tables_list } bool check_dependencies_in_with_clauses(); - bool resolve_references_to_cte_in_hanging_cte(); bool check_cte_dependencies_and_resolve_references(); bool resolve_references_to_cte(TABLE_LIST *tables, TABLE_LIST **tables_last);
1 0
0 0
[Commits] 834e8d6: MDEV-7487 Semi-join optimization for single-table update/delete statements
by IgorBabaev 10 Jan '23

10 Jan '23
revision-id: 834e8d6c4616611b8b7ea91abbca761a1ebabff5 (mariadb-10.11.1-30-g834e8d6) parent(s): 9ebe03afdbf03e713d6ec1184b08a7c34a7e5627 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-09 22:39:39 -0800 message: MDEV-7487 Semi-join optimization for single-table update/delete statements This patch allows to use semi-join optimization at the top level of single-table update and delete statements. The problem of supporting such optimization became easy to resolve after processing a single-table update/delete statement started using JOIN structure. This allowed to use JOIN::prepare() not only for multi-table updates/deletes but for single-table ones as well. This was done in the patch for mdev-28883: Re-design the upper level of handling UPDATE and DELETE statements. Note that JOIN::prepare() detects all subqueries that can be considered as candidates for semi-join optimization. The code added by this patch looks for such candidates at the top level and if such candidates are found in the processed single-table update/delete the statement is handled in the same way as a multi-table update/delete. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/delete_single_to_multi.result | 2409 ++++++++++++++++++++ mysql-test/main/delete_single_to_multi.test | 801 +++++++ mysql-test/main/derived.test | 7 +- mysql-test/main/log_state.result | 2 +- .../main/myisam_explain_non_select_all.result | 45 +- mysql-test/main/opt_trace.result | 20 + mysql-test/main/opt_trace_security.test | 6 +- mysql-test/main/update_single_to_multi.result | 2370 +++++++++++++++++++ mysql-test/main/update_single_to_multi.test | 551 +++++ sql/opt_subselect.cc | 4 +- sql/opt_trace.cc | 3 +- sql/sql_base.cc | 2 +- sql/sql_delete.cc | 5 +- sql/sql_select.cc | 3 +- sql/sql_update.cc | 12 +- 15 files changed, 6199 insertions(+), 41 deletions(-) diff --git a/mysql-test/main/delete_single_to_multi.result b/mysql-test/main/delete_single_to_multi.result new file mode 100644 index 0000000..fe27f69 --- /dev/null +++ b/mysql-test/main/delete_single_to_multi.result @@ -0,0 +1,2409 @@ +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +create index i_n_name on nation(n_name); +analyze table nation; +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status Engine-independent statistics collected +dbt3_s001.nation analyze status OK +# Pullout +# ======= +explain +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +drop table t; +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +create table t as +select * from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +delete from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +insert into partsupp select * from t; +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +drop table t; +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +create table t as +select * from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +delete from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +insert into partsupp select * from t; +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +drop table t; +explain +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +2500 2 0.02 +2500 4 0.02 +4996 1 0.01 +933 1 0.04 +create table t as +select * from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +delete from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +insert into lineitem select * from t; +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +2500 2 0.02 +2500 4 0.02 +4996 1 0.01 +933 1 0.04 +drop table t; +# FirstMatch +# ========== +set optimizer_switch='materialization=off'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +explain +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +drop table t; +set optimizer_switch='materialization=default'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +explain +delete from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +delete from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +drop table t; +# Materialization +# =============== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +drop table t; +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +drop table t; +# Materialization SJM +# =================== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +drop table t; +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +drop table t; +# Pullout PS +# ========== +prepare stmt from " +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +"; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +execute stmt; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +create table r as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +execute stmt; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +insert into orders select * from r; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +drop table t,r; +deallocate prepare stmt; +# FirstMatch PS +# ============= +prepare stmt from " +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +"; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +execute stmt; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table r as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +execute stmt; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +insert into customer select * from r; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +drop table t,r; +deallocate prepare stmt; +# Materialization PS +# ================== +prepare stmt from " +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like ?; +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +set @a1='Customer#%1_'; +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like @a1; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +set @a2='Customer#%3_'; +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like @a2; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +drop table t,r; +deallocate prepare stmt; +# Materialization SJM PS +# ====================== +prepare stmt from " +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_acctbal between ? and ?; +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +set @a1=3500; +set @a2=4000; +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) and c_acctbal between @a1 and @a2; +execute stmt using @a1, @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +set @a3=-1000; +set @a4=3500; +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) and c_acctbal between @a3 and @a4; +execute stmt using @a3, @a4; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +drop table t,r; +deallocate prepare stmt; +# Pullout SP +# ========== +create procedure p(a1 int, a2 int) +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')) and o_totalprice between a1 and a2; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +644 201268.06 +737 12984.85 +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')) and o_totalprice between 150000 and 200000; +call p(150000, 200000); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +644 201268.06 +737 12984.85 +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +644 201268.06 +737 12984.85 +create table r as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')) and o_totalprice between 180000 and 210000; +call p(180000, 210000); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5121 150334.57 +737 12984.85 +insert into orders select * from r; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +644 201268.06 +737 12984.85 +drop table t,r; +drop procedure p; +# FirstMatch SP +# ============= +create procedure p(a int) +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08') and c_acctbal > a; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000019 8914.71 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08') and c_acctbal > 4000; +call p(4000); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000077 1738.87 +Customer#000000092 1182.91 +Customer#000000097 2164.48 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000124 1842.49 +Customer#000000133 2314.67 +Customer#000000142 2209.81 +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000019 8914.71 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table r as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08') and c_acctbal > 2000; +call p(2000); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000077 1738.87 +Customer#000000092 1182.91 +Customer#000000124 1842.49 +insert into customer select * from r; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000019 8914.71 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +drop table t,r; +drop procedure p; +# Materialization SP +# ================== +create procedure p() +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +drop table t,r; +drop procedure p; +# Materialization SJM SP +# ====================== +create procedure p() +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +drop table t,r; +drop procedure p; +# Checking limitations +# ==================== +# Check for DELETE ... RETURNING with SJ subquery in WHERE +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where +2 DEPENDENT SUBQUERY orders index_subquery|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 func 175 (2%) Using where; Using rowid filter +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +insert into customer select * from t; +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +drop table t; +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name +Customer#000000013 +Customer#000000032 +Customer#000000037 +Customer#000000056 +Customer#000000118 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) returning c_name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where +2 DEPENDENT SUBQUERY orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) returning c_name; +c_name +Customer#000000013 +Customer#000000032 +Customer#000000037 +Customer#000000056 +Customer#000000118 +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name +insert into customer select * from t; +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name +Customer#000000013 +Customer#000000032 +Customer#000000037 +Customer#000000056 +Customer#000000118 +drop table t; +# Check for DELETE ... RETURNING with SJ subquery in WHERE +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where +2 DEPENDENT SUBQUERY orders index_subquery|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 func 175 (2%) Using where; Using rowid filter +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +insert into customer select * from t; +drop table t; +# Check for DELETE ... ORDER BY ...LIMIT with SJ subquery in WHERE +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +1856 189361.42 +324 26868.85 +4903 34363.63 +5607 24660.06 +# Should not use semi-join conversion because has ORDER BY ... LIMIT +explain +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY orders range i_o_orderdate i_o_orderdate 4 NULL 108 Using where; Using filesort +2 DEPENDENT SUBQUERY customer unique_subquery|filter PRIMARY,i_c_nationkey PRIMARY|i_c_nationkey 4|5 func 1 (10%) Using where; Using rowid filter +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from t; +o_orderkey o_totalprice +324 26868.85 +1856 189361.42 +1221 117397.16 +4903 34363.63 +5607 24660.06 +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +1856 189361.42 +324 26868.85 +4903 34363.63 +5607 24660.06 +drop table t; +# Should use semi-join converion +explain +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 14 Using index condition +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 12 (7%) Using where; Using rowid filter +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from t; +o_orderkey o_totalprice +1856 189361.42 +324 26868.85 +1221 117397.16 +4903 34363.63 +5607 24660.06 +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +1856 189361.42 +324 26868.85 +4903 34363.63 +5607 24660.06 +drop table t; +DROP DATABASE dbt3_s001; diff --git a/mysql-test/main/delete_single_to_multi.test b/mysql-test/main/delete_single_to_multi.test new file mode 100644 index 0000000..2c49128 --- /dev/null +++ b/mysql-test/main/delete_single_to_multi.test @@ -0,0 +1,801 @@ +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +--enable_warnings +--enable_result_log +--enable_query_log + +create index i_n_name on nation(n_name); +analyze table nation; + + +--echo # Pullout +--echo # ======= + +let $c1= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select o_orderkey, o_totalprice from orders where $c1; +eval +explain format=json +select o_orderkey, o_totalprice from orders where $c1; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table t as +select * from orders where $c1; + +eval +explain +delete from orders where $c1; +eval +explain format=json +delete from orders where $c1; +eval +delete from orders where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + + +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +drop table t; + + +let $c2= + (ps_partkey, ps_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 910 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +eval +create table t as +select * from partsupp where $c2; + +eval +explain +delete from partsupp where $c2; +eval +delete from partsupp where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + +insert into partsupp select * from t; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +drop table t; + + +let $c3= + ps_partkey in (select p_partkey from part + where p_retailprice between 901 and 910) and + ps_suppkey in (select s_suppkey from supplier + where s_nationkey in (select n_nationkey from nation + where n_name='PERU')); +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +eval +create table t as +select * from partsupp where $c3; + +eval +explain +delete from partsupp where $c3; +eval +delete from partsupp where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + +insert into partsupp select * from t; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +drop table t; + + +let $c4= + l_orderkey in (select o_orderkey from orders + where o_custkey in + (select c_custkey from customer + where c_nationkey in + (select n_nationkey from nation + where n_name='PERU')) + and + o_orderDATE between '1992-06-30' and '1992-12-31') + and + (l_partkey, l_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 1000 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +--sorted_result +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +eval +create table t as +select * from lineitem where $c4; + +eval +explain +delete from lineitem where $c4; +eval +delete from lineitem where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + +insert into lineitem select * from t; +--sorted_result +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +drop table t; + + +--echo # FirstMatch +--echo # ========== + +set optimizer_switch='materialization=off'; + +let $c5= + c_nationkey in (select n_nationkey from nation + where n_regionkey in (1,2)) + and + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-10-09' and '1993-06-08'); + +eval +explain +select c_name, c_acctbal from customer where $c5; +eval +explain format=json +select c_name, c_acctbal from customer where $c5; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table t as +select * from customer where $c5; + +eval +explain +delete from customer where $c5; +eval +explain format=json +delete from customer where $c5; +eval +delete from customer where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +drop table t; + +set optimizer_switch='materialization=default'; + + +let $c6= + c_nationkey in (select n_nationkey from nation where n_name='PERU') + and + c_custkey in (select o_custkey from orders + where o_orderDATE between "1992-01-09" and "1993-01-08"); + +eval +explain +select c_name, c_acctbal from customer where $c6; +--sorted_result +eval +select c_name, c_acctbal from customer where $c6; +eval +create table t as +select * from customer where $c6; + +eval +explain +delete from customer where $c6; +eval +delete from customer where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c6; +drop table t; + + +--echo # Materialization +--echo # =============== + +let $c7= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08'); + +eval +explain +select c_name, c_acctbal from customer where $c7; +eval +explain format=json +select c_name, c_acctbal from customer where $c7; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +eval +create table t as +select * from customer where $c7; + +eval +explain +delete from customer where $c7; +eval +explain format=json +delete from customer where $c7; +eval +delete from customer where $c7; +eval +select c_name, c_acctbal from customer where $c7; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +drop table t; + + +let $c8= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-06-09' and '1993-01-08'); + +eval +explain +select c_name, c_acctbal from customer where $c8; +--sorted_result +eval +select c_name, c_acctbal from customer where $c8; +eval +create table t as +select * from customer where $c8; + +eval +explain +delete from customer where $c8; +eval +delete from customer where $c8; +eval +select c_name, c_acctbal from customer where $c8; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c8; +drop table t; + + +--echo # Materialization SJM +--echo # =================== + +let $c9= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); + +eval +explain +select c_name, c_acctbal from customer where $c9; +eval +explain format=json +select c_name, c_acctbal from customer where $c9; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +eval +create table t as +select * from customer where $c9; + +eval +explain +delete from customer where $c9; +eval +explain format=json +delete from customer where $c9; +eval +delete from customer where $c9; +eval +select c_name, c_acctbal from customer where $c9; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +drop table t; + + +let $c10= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); + +eval +explain +select c_name, c_acctbal from customer where $c10; +--sorted_result +eval +select c_name, c_acctbal from customer where $c10; +eval +create table t as +select * from customer where $c10; + +eval +explain +delete from customer where $c10; +eval +delete from customer where $c10; +eval +select c_name, c_acctbal from customer where $c10; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c10; +drop table t; + + +--echo # Pullout PS +--echo # ========== + +eval +prepare stmt from " +delete from orders where $c1; +"; + +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table t as +select * from orders where $c1; +execute stmt; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table r as +select * from orders where $c1; +execute stmt; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from r; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +drop table t,r; + +deallocate prepare stmt; + + +--echo # FirstMatch PS +--echo # ============= + +eval +prepare stmt from " +delete from customer where $c5; +"; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table t as +select * from customer where $c5; +execute stmt; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table r as +select * from customer where $c5; +execute stmt; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +drop table t,r; + +deallocate prepare stmt; + + +--echo # Materialization PS +--echo # ================== + +eval +prepare stmt from " +delete from customer where $c7 and c_name like ?; +"; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +set @a1='Customer#%1_'; +eval +create table t as +select * from customer where $c7 and c_name like @a1; +execute stmt using @a1; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +set @a2='Customer#%3_'; +eval +create table r as +select * from customer where $c7 and c_name like @a2; +execute stmt using @a2; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +drop table t,r; + +deallocate prepare stmt; + + +--echo # Materialization SJM PS +--echo # ====================== + +eval +prepare stmt from " +delete from customer where $c7 and c_acctbal between ? and ?; +"; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +set @a1=3500; +set @a2=4000; +eval +create table t as +select * from customer where $c9 and c_acctbal between @a1 and @a2; +execute stmt using @a1, @a2; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +set @a3=-1000; +set @a4=3500; +eval +create table r as +select * from customer where $c9 and c_acctbal between @a3 and @a4; +execute stmt using @a3, @a4; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +drop table t,r; + +deallocate prepare stmt; + + +--echo # Pullout SP +--echo # ========== + +eval +create procedure p(a1 int, a2 int) +delete from orders where $c1 and o_totalprice between a1 and a2; + +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table t as +select * from orders where $c1 and o_totalprice between 150000 and 200000; +call p(150000, 200000); +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table r as +select * from orders where $c1 and o_totalprice between 180000 and 210000; +call p(180000, 210000); +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from r; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +drop table t,r; + +drop procedure p; + + +--echo # FirstMatch SP +--echo # ============= + +eval +create procedure p(a int) +delete from customer where $c5 and c_acctbal > a; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table t as +select * from customer where $c5 and c_acctbal > 4000; +call p(4000); +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table r as +select * from customer where $c5 and c_acctbal > 2000; +call p(2000); +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +drop table t,r; + +drop procedure p; + + +--echo # Materialization SP +--echo # ================== + +eval +create procedure p() +delete from customer where $c7; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +eval +create table t as +select * from customer where $c7; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +eval +create table r as +select * from customer where $c7; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +drop table t,r; + +drop procedure p; + + +--echo # Materialization SJM SP +--echo # ====================== + +eval +create procedure p() +delete from customer where $c9; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +eval +create table t as +select * from customer where $c9; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +eval +create table r as +select * from customer where $c9; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +drop table t,r; + +drop procedure p; + +--echo # Checking limitations +--echo # ==================== + +--echo # Check for DELETE ... RETURNING with SJ subquery in WHERE + +--sorted_result +eval +select c_name from customer where $c7; +eval +create table t as +select * from customer where $c7; +eval +explain +delete from customer where $c7 returning c_name; +--sorted_result +eval +delete from customer where $c7 returning c_name; +--sorted_result +eval +select c_name from customer where $c7; +insert into customer select * from t; +--sorted_result +eval +select c_name from customer where $c7; +drop table t; + +--sorted_result +eval +select c_name from customer where $c9; +eval +create table t as +select * from customer where $c9; +eval +explain +delete from customer where $c9 returning c_name; +--sorted_result +eval +delete from customer where $c9 returning c_name; +--sorted_result +eval +select c_name from customer where $c9; +insert into customer select * from t; +--sorted_result +eval +select c_name from customer where $c9; +drop table t; + +--echo # Check for DELETE ... RETURNING with SJ subquery in WHERE + +--sorted_result +eval +select c_name from customer where $c7; +eval +create table t as +select * from customer where $c7; +eval +explain +delete from customer where $c7 returning c_name; +--sorted_result +eval +delete from customer where $c7 returning c_name; +--sorted_result +eval +select c_name from customer where $c7; +insert into customer select * from t; +drop table t; + +--echo # Check for DELETE ... ORDER BY ...LIMIT with SJ subquery in WHERE + +let $c11= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (1,2)); + +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; + +--echo # Should not use semi-join conversion because has ORDER BY ... LIMIT +eval +explain +delete from orders where $c11 +order by o_totalprice limit 500; +eval +create table t as +select * from orders where $c11; +select o_orderkey, o_totalprice from t; +eval +delete from orders where $c11 +order by o_totalprice limit 500; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +drop table t; + +--echo # Should use semi-join converion +eval +explain +delete from orders where $c11; +eval +create table t as +select * from orders where $c11; +select o_orderkey, o_totalprice from t; +eval +delete from orders where $c11; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +drop table t; + +DROP DATABASE dbt3_s001; diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test index 338458d..3f916d5 100644 --- a/mysql-test/main/derived.test +++ b/mysql-test/main/derived.test @@ -1128,8 +1128,6 @@ select * from t1 , ( (select t2.a from t2 order by c) union all (select t2.a fr drop table t1,t2,t3; -<<<<<<< 19b8dada4ce79622366d392e092ddb9a6e32b5b5 - --echo # --echo # MDEV-16549: Server crashes in Item_field::fix_fields on query with --echo # view and subquery, Assertion `context' failed, Assertion `field' failed @@ -1148,8 +1146,6 @@ DROP TABLE t1; --echo # --echo # End of 10.3 tests --echo # -======= ---echo # End of 10.3 tests --echo # --echo # MDEV-28883: single/multi-table UPDATE/DELETE whose WHERE condition @@ -1357,5 +1353,4 @@ deallocate prepare stmt; drop table t1,t2,t3; ---echo # End of MariaDB 10.10 tests ->>>>>>> MDEV-28965 Assertion failure when preparing UPDATE with derived table in WHERE +--echo # End of MariaDB 11.0 tests diff --git a/mysql-test/main/log_state.result b/mysql-test/main/log_state.result index 5e7aac8..1b1c737 100644 --- a/mysql-test/main/log_state.result +++ b/mysql-test/main/log_state.result @@ -243,7 +243,7 @@ rows_examined sql_text 4 UPDATE t1 SET a=a+sleep(.02) WHERE a>2 8 UPDATE t1 SET a=a+sleep(.02) ORDER BY a DESC 1 UPDATE t2 set b=b+sleep(.02) limit 1 -4 UPDATE t1 SET a=a+sleep(.02) WHERE a in (SELECT b from t2) +10 UPDATE t1 SET a=a+sleep(.02) WHERE a in (SELECT b from t2) 6 DELETE FROM t1 WHERE a=a+sleep(.02) ORDER BY a LIMIT 2 disconnect con2; connection default; diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 20b769b..5df9ced 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -240,14 +240,16 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -271,8 +273,9 @@ Handler_read_key 5 Handler_read_rnd_next 8 # Status of testing query execution: Variable_name Value -Handler_read_key 4 -Handler_read_rnd_next 5 +Handler_read_key 5 +Handler_read_rnd 3 +Handler_read_rnd_next 12 Handler_update 3 DROP TABLE t1, t2; @@ -290,13 +293,13 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1) FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch(t1) Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 # Status of EXPLAIN EXTENDED query @@ -984,14 +987,16 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1015,8 +1020,8 @@ Handler_read_key 7 Handler_read_rnd_next 8 # Status of testing query execution: Variable_name Value -Handler_read_key 4 -Handler_read_rnd_next 10 +Handler_read_key 7 +Handler_read_rnd_next 8 Handler_update 3 DROP TABLE t1, t2; @@ -1079,14 +1084,14 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where; FirstMatch(t1) FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch(t1) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -3074,14 +3079,14 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 +1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 FirstMatch(t1) 3 DERIVED t2 ALL NULL NULL NULL NULL 3 Using filesort FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 100.00 +1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 100.00 FirstMatch(t1) 3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort # Status of EXPLAIN EXTENDED query Variable_name Value diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index aff8ad9..9ff91cb 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -4153,6 +4153,16 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { } }, { + "table": "t0", + "rowid_filters": [ + { + "key": "a", + "build_cost": 0.174715752, + "rows": 3 + } + ] + }, + { "selectivity_for_indexes": [ { "index_name": "a", @@ -4218,6 +4228,16 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { } }, { + "table": "t1", + "rowid_filters": [ + { + "key": "a", + "build_cost": 0.174715752, + "rows": 3 + } + ] + }, + { "selectivity_for_indexes": [ { "index_name": "a", diff --git a/mysql-test/main/opt_trace_security.test b/mysql-test/main/opt_trace_security.test index 9a4d281..cf45a64 100644 --- a/mysql-test/main/opt_trace_security.test +++ b/mysql-test/main/opt_trace_security.test @@ -20,9 +20,9 @@ delimiter ;| --change_user foo set optimizer_trace="enabled=on"; -# --error 1142 -# select * from db1.t1; -# select * from information_schema.OPTIMIZER_TRACE; +--error 1142 +select * from db1.t1; +select * from information_schema.OPTIMIZER_TRACE; set optimizer_trace="enabled=off"; --change_user root diff --git a/mysql-test/main/update_single_to_multi.result b/mysql-test/main/update_single_to_multi.result new file mode 100644 index 0000000..cc28a0f --- /dev/null +++ b/mysql-test/main/update_single_to_multi.result @@ -0,0 +1,2370 @@ +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +create index i_n_name on nation(n_name); +analyze table nation; +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status Engine-independent statistics collected +dbt3_s001.nation analyze status OK +# Pullout +# ======= +explain +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +explain +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201218.06 +2880 145711.99 +3142 15980.15 +5382 138373.03 +5095 184533.99 +737 12934.85 +1729 12087.76 +5121 150284.57 +update orders set o_totalprice= o_totalprice+50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +update partsupp set ps_supplycost = ps_supplycost+2 where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +update partsupp set ps_supplycost = ps_supplycost+2 where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 446.37 +6 1 644.13 +8 1 959.34 +1 8 359.84 +3 8 647.4 +5 8 52.52 +7 8 765.98 +update partsupp set ps_supplycost = ps_supplycost-2 where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +update partsupp set ps_supplycost = ps_supplycost+10 where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +update partsupp set ps_supplycost = ps_supplycost+10 where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 454.37 +6 1 652.13 +8 1 967.34 +1 8 367.84 +3 8 655.4 +5 8 60.52 +7 8 773.98 +update partsupp set ps_supplycost = ps_supplycost-10 where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +4996 1 0.01 +933 1 0.04 +2500 2 0.02 +2500 4 0.02 +explain +update lineitem set l_tax = (l_tax*100+1)/100 where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +update lineitem set l_tax = (l_tax*100+1)/100 where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +4996 1 0.02 +933 1 0.05 +2500 2 0.03 +2500 4 0.03 +update lineitem set l_tax = (l_tax*100-1)/100 where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +4996 1 0.01 +933 1 0.04 +2500 2 0.02 +2500 4 0.02 +# FirstMatch +# ========== +set optimizer_switch='materialization=off'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +explain +update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9571.95 +Customer#000000008 6829.74 +Customer#000000017 16.34 +Customer#000000019 8924.71 +Customer#000000022 601.98 +Customer#000000025 7143.7 +Customer#000000028 1017.18 +Customer#000000037 -907.75 +Customer#000000040 1345.3 +Customer#000000047 284.58 +Customer#000000059 3468.6 +Customer#000000061 1546.24 +Customer#000000064 -636.64 +Customer#000000067 8176.59 +Customer#000000077 1748.87 +Customer#000000082 9478.34 +Customer#000000091 4653.14 +Customer#000000092 1192.91 +Customer#000000094 5510.11 +Customer#000000097 2174.48 +Customer#000000101 7480.96 +Customer#000000103 2767.45 +Customer#000000106 3298.42 +Customer#000000115 7518.92 +Customer#000000121 6438.32 +Customer#000000122 7875.46 +Customer#000000124 1852.49 +Customer#000000127 9290.71 +Customer#000000130 5083.58 +Customer#000000133 2324.67 +Customer#000000139 7907.78 +Customer#000000142 2219.81 +update customer set c_acctbal = c_acctbal-10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +set optimizer_switch='materialization=default'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +explain +update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6839.74 +Customer#000000035 1248.24 +Customer#000000061 1556.24 +Customer#000000097 2184.48 +Customer#000000121 6448.32 +Customer#000000133 2334.67 +update customer set c_acctbal = c_acctbal-20 where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +# Materialization +# =============== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +explain +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7138.7 +Customer#000000013 3862.34 +Customer#000000065 8800.16 +Customer#000000032 3476.53 +Customer#000000023 3337.02 +Customer#000000035 1233.24 +Customer#000000091 4648.14 +Customer#000000016 4686.03 +Customer#000000098 -546.37 +Customer#000000037 -912.75 +Customer#000000136 -837.39 +Customer#000000118 3587.37 +Customer#000000022 596.98 +Customer#000000005 799.47 +Customer#000000109 -711.1 +Customer#000000038 6350.11 +Customer#000000076 5750.33 +Customer#000000056 6535.86 +Customer#000000040 1340.3 +Customer#000000116 8408.99 +Customer#000000115 7513.92 +Customer#000000140 9968.15 +Customer#000000017 11.34 +Customer#000000052 5635.28 +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +explain +update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 712.56 +Customer#000000002 122.65 +Customer#000000007 9562.95 +Customer#000000008 6820.74 +Customer#000000010 2754.54 +Customer#000000011 -271.6 +Customer#000000016 4682.03 +Customer#000000017 7.34 +Customer#000000019 8915.71 +Customer#000000022 592.98 +Customer#000000023 3333.02 +Customer#000000025 7134.7 +Customer#000000028 1008.18 +Customer#000000029 7619.27 +Customer#000000031 5237.89 +Customer#000000034 8590.7 +Customer#000000037 -916.75 +Customer#000000040 1336.3 +Customer#000000043 9905.28 +Customer#000000044 7316.94 +Customer#000000046 5745.59 +Customer#000000047 275.58 +Customer#000000049 4574.94 +Customer#000000053 4114.64 +Customer#000000055 4573.11 +Customer#000000061 1537.24 +Customer#000000064 -645.64 +Customer#000000067 8167.59 +Customer#000000070 4868.52 +Customer#000000071 -610.19 +Customer#000000073 4289.5 +Customer#000000074 2765.43 +Customer#000000076 5746.33 +Customer#000000079 5122.28 +Customer#000000080 7384.53 +Customer#000000082 9469.34 +Customer#000000083 6464.51 +Customer#000000085 3387.64 +Customer#000000086 3307.32 +Customer#000000088 8032.44 +Customer#000000091 4644.14 +Customer#000000092 1183.91 +Customer#000000095 5328.38 +Customer#000000097 2165.48 +Customer#000000100 9890.89 +Customer#000000101 7471.96 +Customer#000000103 2758.45 +Customer#000000104 -587.38 +Customer#000000106 3289.42 +Customer#000000109 -715.1 +Customer#000000110 7463.99 +Customer#000000112 2954.35 +Customer#000000118 3583.37 +Customer#000000121 6429.32 +Customer#000000122 7866.46 +Customer#000000127 9281.71 +Customer#000000130 5074.58 +Customer#000000131 8596.53 +Customer#000000133 2315.67 +Customer#000000134 4609.9 +Customer#000000136 -841.39 +Customer#000000137 7839.3 +Customer#000000139 7898.78 +Customer#000000142 2210.81 +Customer#000000143 2187.5 +Customer#000000148 2136.6 +Customer#000000149 8960.65 +update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +# Materialization SJM +# =================== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +explain +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3852.34 +Customer#000000032 3466.53 +Customer#000000037 -922.75 +Customer#000000118 3577.37 +Customer#000000056 6525.86 +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +explain +update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9560.95 +Customer#000000016 4680.03 +Customer#000000037 -918.75 +Customer#000000046 5743.59 +Customer#000000091 4642.14 +Customer#000000103 2756.45 +Customer#000000118 3581.37 +Customer#000000133 2313.67 +Customer#000000134 4607.9 +update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +# Pullout PS +# ========== +prepare stmt from " +update orders set o_totalprice = o_totalprice+? where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +"; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +set @a1=-20; +execute stmt using @a1; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201248.06 +2880 145741.99 +3142 16010.15 +5382 138403.03 +5095 184563.99 +737 12964.85 +1729 12117.76 +5121 150314.57 +set @a2=-10; +execute stmt using @a2; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201238.06 +2880 145731.99 +3142 16000.15 +5382 138393.03 +5095 184553.99 +737 12954.85 +1729 12107.76 +5121 150304.57 +execute stmt using -(@a1+@a2); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +deallocate prepare stmt; +# FirstMatch PS +# ============= +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +"; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +set @a1=15; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3473.6 +Customer#000000106 3303.42 +Customer#000000017 21.34 +Customer#000000047 289.58 +Customer#000000092 1197.91 +Customer#000000101 7485.96 +Customer#000000022 606.98 +Customer#000000040 1350.3 +Customer#000000064 -631.64 +Customer#000000122 7880.46 +Customer#000000028 1022.18 +Customer#000000037 -902.75 +Customer#000000091 4658.14 +Customer#000000115 7523.92 +Customer#000000067 8181.59 +Customer#000000094 5515.11 +Customer#000000103 2772.45 +Customer#000000130 5088.58 +Customer#000000139 7912.78 +Customer#000000142 2224.81 +Customer#000000025 7148.7 +Customer#000000008 6834.74 +Customer#000000061 1551.24 +Customer#000000077 1753.87 +Customer#000000097 2179.48 +Customer#000000121 6443.32 +Customer#000000133 2329.67 +Customer#000000007 9576.95 +Customer#000000019 8929.71 +Customer#000000082 9483.34 +Customer#000000124 1857.49 +Customer#000000127 9295.71 +set @a2=5; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3478.6 +Customer#000000106 3308.42 +Customer#000000017 26.34 +Customer#000000047 294.58 +Customer#000000092 1202.91 +Customer#000000101 7490.96 +Customer#000000022 611.98 +Customer#000000040 1355.3 +Customer#000000064 -626.64 +Customer#000000122 7885.46 +Customer#000000028 1027.1799999999998 +Customer#000000037 -897.75 +Customer#000000091 4663.14 +Customer#000000115 7528.92 +Customer#000000067 8186.59 +Customer#000000094 5520.11 +Customer#000000103 2777.45 +Customer#000000130 5093.58 +Customer#000000139 7917.78 +Customer#000000142 2229.81 +Customer#000000025 7153.7 +Customer#000000008 6839.74 +Customer#000000061 1556.24 +Customer#000000077 1758.87 +Customer#000000097 2184.48 +Customer#000000121 6448.32 +Customer#000000133 2334.67 +Customer#000000007 9581.95 +Customer#000000019 8934.71 +Customer#000000082 9488.34 +Customer#000000124 1862.49 +Customer#000000127 9300.71 +execute stmt using -(@a1+@a2); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.1799999999998 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +deallocate prepare stmt; +# Materialization PS +# ================== +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +set @a1=7; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7140.7 +Customer#000000013 3864.34 +Customer#000000065 8802.16 +Customer#000000032 3478.53 +Customer#000000023 3339.02 +Customer#000000035 1235.24 +Customer#000000091 4650.14 +Customer#000000016 4688.03 +Customer#000000098 -544.37 +Customer#000000037 -910.75 +Customer#000000136 -835.39 +Customer#000000118 3589.37 +Customer#000000022 598.98 +Customer#000000005 801.47 +Customer#000000109 -709.1 +Customer#000000038 6352.11 +Customer#000000076 5752.33 +Customer#000000056 6537.86 +Customer#000000040 1342.3 +Customer#000000116 8410.99 +Customer#000000115 7515.92 +Customer#000000140 9970.15 +Customer#000000017 13.34 +Customer#000000052 5637.28 +set @a2=3; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7143.7 +Customer#000000013 3867.34 +Customer#000000065 8805.16 +Customer#000000032 3481.53 +Customer#000000023 3342.02 +Customer#000000035 1238.24 +Customer#000000091 4653.14 +Customer#000000016 4691.03 +Customer#000000098 -541.37 +Customer#000000037 -907.75 +Customer#000000136 -832.39 +Customer#000000118 3592.37 +Customer#000000022 601.98 +Customer#000000005 804.47 +Customer#000000109 -706.1 +Customer#000000038 6355.11 +Customer#000000076 5755.33 +Customer#000000056 6540.86 +Customer#000000040 1345.3 +Customer#000000116 8413.99 +Customer#000000115 7518.92 +Customer#000000140 9973.15 +Customer#000000017 16.34 +Customer#000000052 5640.28 +execute stmt using -(@a1+@a2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +deallocate prepare stmt; +# Materialization SJM PS +# ====================== +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +set @a1=-2; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3855.34 +Customer#000000032 3469.53 +Customer#000000037 -919.75 +Customer#000000118 3580.37 +Customer#000000056 6528.86 +set @a2=-1; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3854.34 +Customer#000000032 3468.53 +Customer#000000037 -920.75 +Customer#000000118 3579.37 +Customer#000000056 6527.86 +execute stmt using -(@a1+@a2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +deallocate prepare stmt; +# Pullout SP +# ========== +create procedure p(d int) +update orders set o_totalprice = o_totalprice+d where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +call p(-10); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201258.06 +2880 145751.99 +3142 16020.15 +5382 138413.03 +5095 184573.99 +737 12974.85 +1729 12127.76 +5121 150324.57 +call p(-20); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201238.06 +2880 145731.99 +3142 16000.15 +5382 138393.03 +5095 184553.99 +737 12954.85 +1729 12107.76 +5121 150304.57 +call p(10+20); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +drop procedure p; +# FirstMatch SP +# ============= +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.1799999999998 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +call p(5); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3463.6 +Customer#000000106 3293.42 +Customer#000000017 11.34 +Customer#000000047 279.58 +Customer#000000092 1187.91 +Customer#000000101 7475.96 +Customer#000000022 596.98 +Customer#000000040 1340.3 +Customer#000000064 -641.64 +Customer#000000122 7870.46 +Customer#000000028 1012.1799999999998 +Customer#000000037 -912.75 +Customer#000000091 4648.14 +Customer#000000115 7513.92 +Customer#000000067 8171.59 +Customer#000000094 5505.11 +Customer#000000103 2762.45 +Customer#000000130 5078.58 +Customer#000000139 7902.78 +Customer#000000142 2214.81 +Customer#000000025 7138.7 +Customer#000000008 6824.74 +Customer#000000061 1541.24 +Customer#000000077 1743.87 +Customer#000000097 2169.48 +Customer#000000121 6433.32 +Customer#000000133 2319.67 +Customer#000000007 9566.95 +Customer#000000019 8919.71 +Customer#000000082 9473.34 +Customer#000000124 1847.49 +Customer#000000127 9285.71 +call p(15); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3478.6 +Customer#000000106 3308.42 +Customer#000000017 26.34 +Customer#000000047 294.58 +Customer#000000092 1202.91 +Customer#000000101 7490.96 +Customer#000000022 611.98 +Customer#000000040 1355.3 +Customer#000000064 -626.64 +Customer#000000122 7885.46 +Customer#000000028 1027.1799999999998 +Customer#000000037 -897.75 +Customer#000000091 4663.14 +Customer#000000115 7528.92 +Customer#000000067 8186.59 +Customer#000000094 5520.11 +Customer#000000103 2777.45 +Customer#000000130 5093.58 +Customer#000000139 7917.78 +Customer#000000142 2229.81 +Customer#000000025 7153.7 +Customer#000000008 6839.74 +Customer#000000061 1556.24 +Customer#000000077 1758.87 +Customer#000000097 2184.48 +Customer#000000121 6448.32 +Customer#000000133 2334.67 +Customer#000000007 9581.95 +Customer#000000019 8934.71 +Customer#000000082 9488.34 +Customer#000000124 1862.49 +Customer#000000127 9300.71 +call p(-(5+15)); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.1799999999998 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +drop procedure p; +# Materialization SP +# ================== +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +call p(3); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7136.7 +Customer#000000013 3860.34 +Customer#000000065 8798.16 +Customer#000000032 3474.53 +Customer#000000023 3335.02 +Customer#000000035 1231.24 +Customer#000000091 4646.14 +Customer#000000016 4684.03 +Customer#000000098 -548.37 +Customer#000000037 -914.75 +Customer#000000136 -839.39 +Customer#000000118 3585.37 +Customer#000000022 594.98 +Customer#000000005 797.47 +Customer#000000109 -713.1 +Customer#000000038 6348.11 +Customer#000000076 5748.33 +Customer#000000056 6533.86 +Customer#000000040 1338.3 +Customer#000000116 8406.99 +Customer#000000115 7511.92 +Customer#000000140 9966.15 +Customer#000000017 9.34 +Customer#000000052 5633.28 +call p(7); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7143.7 +Customer#000000013 3867.34 +Customer#000000065 8805.16 +Customer#000000032 3481.53 +Customer#000000023 3342.02 +Customer#000000035 1238.24 +Customer#000000091 4653.14 +Customer#000000016 4691.03 +Customer#000000098 -541.37 +Customer#000000037 -907.75 +Customer#000000136 -832.39 +Customer#000000118 3592.37 +Customer#000000022 601.98 +Customer#000000005 804.47 +Customer#000000109 -706.1 +Customer#000000038 6355.11 +Customer#000000076 5755.33 +Customer#000000056 6540.86 +Customer#000000040 1345.3 +Customer#000000116 8413.99 +Customer#000000115 7518.92 +Customer#000000140 9973.15 +Customer#000000017 16.34 +Customer#000000052 5640.28 +call p(-(3+7)); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +drop procedure p; +# Materialization SJM SP +# ====================== +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +call p(-1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3856.34 +Customer#000000032 3470.53 +Customer#000000037 -918.75 +Customer#000000118 3581.37 +Customer#000000056 6529.86 +call p(-2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3854.34 +Customer#000000032 3468.53 +Customer#000000037 -920.75 +Customer#000000118 3579.37 +Customer#000000056 6527.86 +call p(1+2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +drop procedure p; +# Checking limitations +# ==================== +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +324 26868.85 +1856 189361.42 +1344 43809.37 +1925 146382.71 +3139 40975.96 +4903 34363.63 +5607 24660.06 +# Should not use semi-join conversion because has ORDER BY ... LIMIT +explain +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY orders range i_o_orderdate i_o_orderdate 4 NULL 108 Using where; Using filesort +2 DEPENDENT SUBQUERY customer unique_subquery|filter PRIMARY,i_c_nationkey PRIMARY|i_c_nationkey 4|5 func 1 (10%) Using where; Using rowid filter +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117347.16 +324 26818.85 +1856 189311.42 +1344 43759.37 +1925 146332.71 +3139 40925.96 +4903 34313.63 +5607 24610.06 +update orders set o_totalprice = o_totalprice+50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +324 26868.85 +1856 189361.42 +1344 43809.37 +1925 146382.71 +3139 40975.96 +4903 34363.63 +5607 24660.06 +# Should use semi-join converion +explain +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 15 Using index condition +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117347.16 +324 26818.85 +1856 189311.42 +1344 43759.37 +1925 146332.71 +3139 40925.96 +4903 34313.63 +5607 24610.06 +update orders set o_totalprice = o_totalprice+50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +324 26868.85 +1856 189361.42 +1344 43809.37 +1925 146382.71 +3139 40975.96 +4903 34363.63 +5607 24660.06 +DROP DATABASE dbt3_s001; diff --git a/mysql-test/main/update_single_to_multi.test b/mysql-test/main/update_single_to_multi.test new file mode 100644 index 0000000..bf89a6c --- /dev/null +++ b/mysql-test/main/update_single_to_multi.test @@ -0,0 +1,551 @@ +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +--enable_warnings +--enable_result_log +--enable_query_log + +create index i_n_name on nation(n_name); +analyze table nation; + + +--echo # Pullout +--echo # ======= + +let $c1= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select o_orderkey, o_totalprice from orders where $c1; +eval +explain format=json +select o_orderkey, o_totalprice from orders where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + +eval +explain +update orders set o_totalprice = o_totalprice-50 where $c1; +eval +explain format=json +update orders set o_totalprice = o_totalprice-50 where $c1; +eval +update orders set o_totalprice = o_totalprice-50 where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + +eval +update orders set o_totalprice= o_totalprice+50 where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + + +let $c2= + (ps_partkey, ps_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 910 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + +eval +explain +update partsupp set ps_supplycost = ps_supplycost+2 where $c2; +eval +update partsupp set ps_supplycost = ps_supplycost+2 where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + +eval +update partsupp set ps_supplycost = ps_supplycost-2 where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + + +let $c3= + ps_partkey in (select p_partkey from part + where p_retailprice between 901 and 910) and + ps_suppkey in (select s_suppkey from supplier + where s_nationkey in (select n_nationkey from nation + where n_name='PERU')); +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + +eval +explain +update partsupp set ps_supplycost = ps_supplycost+10 where $c3; +eval +update partsupp set ps_supplycost = ps_supplycost+10 where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + +eval +update partsupp set ps_supplycost = ps_supplycost-10 where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + + +let $c4= + l_orderkey in (select o_orderkey from orders + where o_custkey in + (select c_custkey from customer + where c_nationkey in + (select n_nationkey from nation + where n_name='PERU')) + and + o_orderDATE between '1992-06-30' and '1992-12-31') + and + (l_partkey, l_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 1000 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + +eval +explain +update lineitem set l_tax = (l_tax*100+1)/100 where $c4; +eval +update lineitem set l_tax = (l_tax*100+1)/100 where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + +eval +update lineitem set l_tax = (l_tax*100-1)/100 where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + + +--echo # FirstMatch +--echo # ========== + +set optimizer_switch='materialization=off'; + +let $c5= + c_nationkey in (select n_nationkey from nation + where n_regionkey in (1,2)) + and + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-10-09' and '1993-06-08'); + +eval +explain +select c_name, c_acctbal from customer where $c5; +eval +explain format=json +select c_name, c_acctbal from customer where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +eval +explain +update customer set c_acctbal = c_acctbal+10 where $c5; +eval +explain format=json +update customer set c_acctbal = c_acctbal+10 where $c5; +eval +update customer set c_acctbal = c_acctbal+10 where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +eval +update customer set c_acctbal = c_acctbal-10 where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +set optimizer_switch='materialization=default'; + +let $c6= + c_nationkey in (select n_nationkey from nation where n_name='PERU') + and + c_custkey in (select o_custkey from orders + where o_orderDATE between "1992-01-09" and "1993-01-08"); + +eval +explain +select c_name, c_acctbal from customer where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +eval +explain +update customer set c_acctbal = c_acctbal+20 where $c6; +eval +update customer set c_acctbal = c_acctbal+20 where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +eval +update customer set c_acctbal = c_acctbal-20 where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +--echo # Materialization +--echo # =============== + +let $c7= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08'); + +eval +explain +select c_name, c_acctbal from customer where $c7; +eval +explain format=json +select c_name, c_acctbal from customer where $c7; +eval +select c_name, c_acctbal from customer where $c7; + +eval +explain +update customer set c_acctbal = c_acctbal+5 where $c7; +eval +explain format=json +update customer set c_acctbal = c_acctbal+5 where $c7; +eval +update customer set c_acctbal = c_acctbal+5 where $c7; +eval +select c_name, c_acctbal from customer where $c7; + +eval +update customer set c_acctbal = c_acctbal-5 where $c7; +eval +select c_name, c_acctbal from customer where $c7; + + +let $c8= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-06-09' and '1993-01-08'); + +eval +explain +select c_name, c_acctbal from customer where $c8; +eval +select c_name, c_acctbal from customer where $c8; + +eval +explain +update customer set c_acctbal = c_acctbal+1 where $c8; +eval +update customer set c_acctbal = c_acctbal+1 where $c8; +eval +select c_name, c_acctbal from customer where $c8; + +eval +update customer set c_acctbal = c_acctbal-1 where $c8; +eval +select c_name, c_acctbal from customer where $c8; + + +--echo # Materialization SJM +--echo # =================== + +let $c9= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); + +eval +explain +select c_name, c_acctbal from customer where $c9; +eval +explain format=json +select c_name, c_acctbal from customer where $c9; +eval +select c_name, c_acctbal from customer where $c9; + +eval +explain +update customer set c_acctbal = c_acctbal-5 where $c9; +eval +explain format=json +update customer set c_acctbal = c_acctbal-5 where $c9; +eval +update customer set c_acctbal = c_acctbal-5 where $c9; +eval +select c_name, c_acctbal from customer where $c9; + +eval +update customer set c_acctbal = c_acctbal+5 where $c9; +eval +select c_name, c_acctbal from customer where $c9; + + +let $c10= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); + +eval +explain +select c_name, c_acctbal from customer where $c10; +eval +select c_name, c_acctbal from customer where $c10; + +eval +explain +update customer set c_acctbal = c_acctbal-1 where $c10; +eval +update customer set c_acctbal = c_acctbal-1 where $c10; +eval +select c_name, c_acctbal from customer where $c10; + +eval +update customer set c_acctbal = c_acctbal+1 where $c10; +eval +select c_name, c_acctbal from customer where $c10; + + +--echo # Pullout PS +--echo # ========== + +eval +prepare stmt from " +update orders set o_totalprice = o_totalprice+? where $c1; +"; + +eval +select o_orderkey, o_totalprice from orders where $c1; +set @a1=-20; +execute stmt using @a1; +eval +select o_orderkey, o_totalprice from orders where $c1; +set @a2=-10; +execute stmt using @a2; +eval +select o_orderkey, o_totalprice from orders where $c1; +execute stmt using -(@a1+@a2); +eval +select o_orderkey, o_totalprice from orders where $c1; + +deallocate prepare stmt; + + +--echo # FirstMatch PS +--echo # ============= + +eval +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where $c5; +"; + +eval +select c_name, c_acctbal from customer where $c5; +set @a1=15; +execute stmt using @a1; +eval +select c_name, c_acctbal from customer where $c5; +set @a2=5; +execute stmt using @a2; +eval +select c_name, c_acctbal from customer where $c5; +execute stmt using -(@a1+@a2); +eval +select c_name, c_acctbal from customer where $c5; + +deallocate prepare stmt; + + +--echo # Materialization PS +--echo # ================== + +eval +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where $c7; +"; + +eval +select c_name, c_acctbal from customer where $c7; +set @a1=7; +execute stmt using @a1; +eval +select c_name, c_acctbal from customer where $c7; +set @a2=3; +execute stmt using @a2; +eval +select c_name, c_acctbal from customer where $c7; +execute stmt using -(@a1+@a2); +eval +select c_name, c_acctbal from customer where $c7; + +deallocate prepare stmt; + + +--echo # Materialization SJM PS +--echo # ====================== + +eval +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where $c9; +"; + +eval +select c_name, c_acctbal from customer where $c9; +set @a1=-2; +execute stmt using @a1; +eval +select c_name, c_acctbal from customer where $c9; +set @a2=-1; +execute stmt using @a2; +eval +select c_name, c_acctbal from customer where $c9; +execute stmt using -(@a1+@a2); +eval +select c_name, c_acctbal from customer where $c9; + +deallocate prepare stmt; + + +--echo # Pullout SP +--echo # ========== + +eval +create procedure p(d int) +update orders set o_totalprice = o_totalprice+d where $c1; + +eval +select o_orderkey, o_totalprice from orders where $c1; +call p(-10); +eval +select o_orderkey, o_totalprice from orders where $c1; +call p(-20); +eval +select o_orderkey, o_totalprice from orders where $c1; +call p(10+20); +eval +select o_orderkey, o_totalprice from orders where $c1; + +drop procedure p; + + +--echo # FirstMatch SP +--echo # ============= + +eval +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where $c5; + +eval +select c_name, c_acctbal from customer where $c5; +call p(5); +eval +select c_name, c_acctbal from customer where $c5; +call p(15); +eval +select c_name, c_acctbal from customer where $c5; +call p(-(5+15)); +eval +select c_name, c_acctbal from customer where $c5; + +drop procedure p; + + +--echo # Materialization SP +--echo # ================== + +eval +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where $c7; + +eval +select c_name, c_acctbal from customer where $c7; +call p(3); +eval +select c_name, c_acctbal from customer where $c7; +call p(7); +eval +select c_name, c_acctbal from customer where $c7; +call p(-(3+7)); +eval +select c_name, c_acctbal from customer where $c7; + +drop procedure p; + + +--echo # Materialization SJM SP +--echo # ====================== + +eval +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where $c9; + +eval +select c_name, c_acctbal from customer where $c9; +call p(-1); +eval +select c_name, c_acctbal from customer where $c9; +call p(-2); +eval +select c_name, c_acctbal from customer where $c9; +call p(1+2); +eval +select c_name, c_acctbal from customer where $c9; + +drop procedure p; + +--echo # Checking limitations +--echo # ==================== + +let $c11= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (1,2)); + +eval +select o_orderkey, o_totalprice from orders where $c11; +--echo # Should not use semi-join conversion because has ORDER BY ... LIMIT +eval +explain +update orders set o_totalprice = o_totalprice-50 where $c11 +order by o_totalprice limit 500; +eval +update orders set o_totalprice = o_totalprice-50 where $c11 +order by o_totalprice limit 500; +eval +select o_orderkey, o_totalprice from orders where $c11; +eval +update orders set o_totalprice = o_totalprice+50 where $c11 +order by o_totalprice limit 500; +eval +select o_orderkey, o_totalprice from orders where $c11; + +--echo # Should use semi-join converion +eval +explain +update orders set o_totalprice = o_totalprice-50 where $c11; +eval +update orders set o_totalprice = o_totalprice-50 where $c11; +eval +select o_orderkey, o_totalprice from orders where $c11; +eval +update orders set o_totalprice = o_totalprice+50 where $c11; +eval +select o_orderkey, o_totalprice from orders where $c11; + +DROP DATABASE dbt3_s001; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index bddaa1b..87201f5 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -565,11 +565,11 @@ bool SELECT_LEX::is_sj_conversion_prohibited(THD *thd) switch (thd->lex->sql_command) { case SQLCOM_UPDATE: return - !((Sql_cmd_update *) cmd)->is_multitable() || + !((Sql_cmd_update *) cmd)->is_multitable() && ((Sql_cmd_update *) cmd)->processing_as_multitable_update_prohibited(thd); case SQLCOM_DELETE: return - !((Sql_cmd_delete *) cmd)->is_multitable() || + !((Sql_cmd_delete *) cmd)->is_multitable() && ((Sql_cmd_delete *) cmd)->processing_as_multitable_delete_prohibited(thd); default: return false; diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index 33209ff..4bc4939 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -491,8 +491,7 @@ void Opt_trace_start::init(THD *thd, !list_has_optimizer_trace_table(tbl) && !sets_var_optimizer_trace(sql_command, set_vars) && !thd->system_thread && - !ctx->disable_tracing_if_required() && - !(thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_PREPARE)) + !ctx->disable_tracing_if_required()) { ctx->start(thd, tbl, sql_command, query, query_length, query_charset, thd->variables.optimizer_trace_max_mem_size); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6726bff..e6dad17 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1214,7 +1214,7 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, } } else if (thd->lex->sql_command == SQLCOM_DELETE) - { + { Sql_cmd_delete *cmd= (Sql_cmd_delete *) (thd->lex->m_sql_cmd); if (cmd->is_multitable() || derived->derived->outer_select()) materialize= false; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 052a439..64321f0 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -348,7 +348,6 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd) query_plan.using_filesort= FALSE; THD_STAGE_INFO(thd, stage_init_update); - create_explain_query(thd->lex, thd->mem_root); const bool delete_history= table_list->vers_conditions.delete_history; DBUG_ASSERT(!(delete_history && table_list->period_conditions.is_set())); @@ -1666,6 +1665,10 @@ bool Sql_cmd_delete::prepare_inner(THD *thd) { goto err; } + + if (!multitable && + select_lex->sj_subselects.elements) + multitable= true; } if (multitable) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9b2e993..9e2d684 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5891,8 +5891,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, s->needed_reg=select->needed_reg; select->quick=0; impossible_range= records == 0 && s->table->reginfo.impossible_range; - if (join->thd->lex->sql_command == SQLCOM_SELECT && - optimizer_flag(join->thd, OPTIMIZER_SWITCH_USE_ROWID_FILTER)) + if (optimizer_flag(join->thd, OPTIMIZER_SWITCH_USE_ROWID_FILTER)) s->table->init_cost_info_for_usable_range_rowid_filters(join->thd); } if (!impossible_range) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index f50f412..1a7451a 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -382,7 +382,6 @@ bool Sql_cmd_update::update_single_table(THD *thd) DBUG_ENTER("Sql_cmd_update::update_single_table"); THD_STAGE_INFO(thd, stage_init_update); - create_explain_query(thd->lex, thd->mem_root); thd->table_map_for_update= 0; @@ -2476,6 +2475,8 @@ int multi_update::do_updates() table = cur_table->table; if (table == table_to_update) continue; // Already updated + if (table->file->pushed_rowid_filter) + table->file->disable_pushed_rowid_filter(); org_updated= updated; tmp_table= tmp_tables[cur_table->shared]; tmp_table->file->extra(HA_EXTRA_CACHE); // Change to read cache @@ -2670,7 +2671,8 @@ int multi_update::do_updates() check_opt_it.rewind(); while (TABLE *tbl= check_opt_it++) tbl->file->ha_rnd_end(); - + if (table->file->save_pushed_rowid_filter) + table->file->enable_pushed_rowid_filter(); } DBUG_RETURN(0); @@ -2681,6 +2683,8 @@ int multi_update::do_updates() } err2: + if (table->file->save_pushed_rowid_filter) + table->file->enable_pushed_rowid_filter(); if (table->file->inited) (void) table->file->ha_rnd_end(); if (tmp_table->file->inited) @@ -2984,7 +2988,9 @@ bool Sql_cmd_update::prepare_inner(THD *thd) { goto err; } - + if (!multitable && + select_lex->sj_subselects.elements) + multitable= true; } if (table_list->has_period())
1 0
0 0
[Commits] caf4009: MDEV-7487 Semi-join optimization for single-table update/delete statements
by IgorBabaev 10 Jan '23

10 Jan '23
revision-id: caf4009f43c2241615af9e1700bb1f0918eed703 (mariadb-10.11.1-30-gcaf4009) parent(s): 9ebe03afdbf03e713d6ec1184b08a7c34a7e5627 author: Igor Babaev committer: Igor Babaev timestamp: 2023-01-09 22:30:33 -0800 message: MDEV-7487 Semi-join optimization for single-table update/delete statements This patch allows to use semi-join optimization at the top level of single-table update and delete statements. The problem of supporting such optimization became easy to resolve after processing a single-table update/delete statement started using JOIN structure. This allowed to use JOIN::prepare() not only for multi-table updates/deletes but for single-table ones as well. This was done in the patch for mdev-28883: Re-design the upper level of handling UPDATE and DELETE statements. Note that JOIN::prepare() detects all subqueries that can be considered as candidates for semi-join optimization. The code added by this patch looks for such candidates at the top level and if such candidates are found in the processed single-table update/delete the statement is handled in the same way as a multi-table update/delete. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/delete_single_to_multi.result | 2409 ++++++++++++++++++++ mysql-test/main/delete_single_to_multi.test | 801 +++++++ mysql-test/main/derived.test | 7 +- mysql-test/main/log_state.result | 2 +- .../main/myisam_explain_non_select_all.result | 45 +- mysql-test/main/opt_trace.result | 20 + mysql-test/main/opt_trace_security.test | 6 +- mysql-test/main/update_single_to_multi.result | 2384 +++++++++++++++++++ mysql-test/main/update_single_to_multi.test | 553 +++++ sql/opt_subselect.cc | 4 +- sql/opt_trace.cc | 3 +- sql/sql_base.cc | 2 +- sql/sql_delete.cc | 6 + sql/sql_select.cc | 3 +- sql/sql_update.cc | 13 +- 15 files changed, 6219 insertions(+), 39 deletions(-) diff --git a/mysql-test/main/delete_single_to_multi.result b/mysql-test/main/delete_single_to_multi.result new file mode 100644 index 0000000..fe27f69 --- /dev/null +++ b/mysql-test/main/delete_single_to_multi.result @@ -0,0 +1,2409 @@ +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +create index i_n_name on nation(n_name); +analyze table nation; +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status Engine-independent statistics collected +dbt3_s001.nation analyze status OK +# Pullout +# ======= +explain +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +drop table t; +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +create table t as +select * from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +delete from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +insert into partsupp select * from t; +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +drop table t; +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +create table t as +select * from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +delete from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +insert into partsupp select * from t; +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +1 8 357.84 +3 8 645.4 +4 1 444.37 +5 8 50.52 +6 1 642.13 +7 8 763.98 +8 1 957.34 +drop table t; +explain +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +2500 2 0.02 +2500 4 0.02 +4996 1 0.01 +933 1 0.04 +create table t as +select * from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +explain +delete from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +delete from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +insert into lineitem select * from t; +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +2500 2 0.02 +2500 4 0.02 +4996 1 0.01 +933 1 0.04 +drop table t; +# FirstMatch +# ========== +set optimizer_switch='materialization=off'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +explain +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +drop table t; +set optimizer_switch='materialization=default'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +explain +delete from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +delete from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +drop table t; +# Materialization +# =============== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +drop table t; +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +drop table t; +# Materialization SJM +# =================== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +drop table t; +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +drop table t; +# Pullout PS +# ========== +prepare stmt from " +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +"; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +execute stmt; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +create table r as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +execute stmt; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +insert into orders select * from r; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +5382 138423.03 +644 201268.06 +737 12984.85 +drop table t,r; +deallocate prepare stmt; +# FirstMatch PS +# ============= +prepare stmt from " +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +"; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +execute stmt; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table r as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +execute stmt; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +insert into customer select * from r; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +drop table t,r; +deallocate prepare stmt; +# Materialization PS +# ================== +prepare stmt from " +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like ?; +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +set @a1='Customer#%1_'; +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like @a1; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +set @a2='Customer#%3_'; +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like @a2; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000005 794.47 +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000035 1228.24 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000040 1335.3 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000098 -551.37 +Customer#000000109 -716.1 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000136 -842.39 +Customer#000000140 9963.15 +drop table t,r; +deallocate prepare stmt; +# Materialization SJM PS +# ====================== +prepare stmt from " +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') and c_acctbal between ? and ?; +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +set @a1=3500; +set @a2=4000; +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) and c_acctbal between @a1 and @a2; +execute stmt using @a1, @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +set @a3=-1000; +set @a4=3500; +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) and c_acctbal between @a3 and @a4; +execute stmt using @a3, @a4; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +drop table t,r; +deallocate prepare stmt; +# Pullout SP +# ========== +create procedure p(a1 int, a2 int) +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')) and o_totalprice between a1 and a2; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +644 201268.06 +737 12984.85 +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')) and o_totalprice between 150000 and 200000; +call p(150000, 200000); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +644 201268.06 +737 12984.85 +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +644 201268.06 +737 12984.85 +create table r as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')) and o_totalprice between 180000 and 210000; +call p(180000, 210000); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5121 150334.57 +737 12984.85 +insert into orders select * from r; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +1729 12137.76 +2880 145761.99 +3142 16030.15 +5095 184583.99 +5121 150334.57 +644 201268.06 +737 12984.85 +drop table t,r; +drop procedure p; +# FirstMatch SP +# ============= +create procedure p(a int) +delete from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08') and c_acctbal > a; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000019 8914.71 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table t as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08') and c_acctbal > 4000; +call p(4000); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000077 1738.87 +Customer#000000092 1182.91 +Customer#000000097 2164.48 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000124 1842.49 +Customer#000000133 2314.67 +Customer#000000142 2209.81 +insert into customer select * from t; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000019 8914.71 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +create table r as +select * from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08') and c_acctbal > 2000; +call p(2000); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000077 1738.87 +Customer#000000092 1182.91 +Customer#000000124 1842.49 +insert into customer select * from r; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000019 8914.71 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +drop table t,r; +drop procedure p; +# Materialization SP +# ================== +create procedure p() +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000016 4681.03 +Customer#000000025 7133.7 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000038 6345.11 +Customer#000000052 5630.28 +Customer#000000056 6530.86 +Customer#000000065 8795.16 +Customer#000000076 5745.33 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000116 8403.99 +Customer#000000118 3582.37 +Customer#000000140 9963.15 +drop table t,r; +drop procedure p; +# Materialization SJM SP +# ====================== +create procedure p() +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +insert into customer select * from t; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +create table r as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +call p(); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +insert into customer select * from r; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000056 6530.86 +Customer#000000118 3582.37 +drop table t,r; +drop procedure p; +# Checking limitations +# ==================== +# Check for DELETE ... RETURNING with SJ subquery in WHERE +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where +2 DEPENDENT SUBQUERY orders index_subquery|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 func 175 (2%) Using where; Using rowid filter +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +insert into customer select * from t; +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +drop table t; +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name +Customer#000000013 +Customer#000000032 +Customer#000000037 +Customer#000000056 +Customer#000000118 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) returning c_name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where +2 DEPENDENT SUBQUERY orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1) returning c_name; +c_name +Customer#000000013 +Customer#000000032 +Customer#000000037 +Customer#000000056 +Customer#000000118 +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name +insert into customer select * from t; +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name +Customer#000000013 +Customer#000000032 +Customer#000000037 +Customer#000000056 +Customer#000000118 +drop table t; +# Check for DELETE ... RETURNING with SJ subquery in WHERE +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +create table t as +select * from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +explain +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where +2 DEPENDENT SUBQUERY orders index_subquery|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 func 175 (2%) Using where; Using rowid filter +delete from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name; +c_name +Customer#000000013 +Customer#000000016 +Customer#000000025 +Customer#000000032 +Customer#000000037 +Customer#000000038 +Customer#000000052 +Customer#000000056 +Customer#000000065 +Customer#000000076 +Customer#000000091 +Customer#000000115 +Customer#000000116 +Customer#000000118 +Customer#000000140 +select c_name from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name +insert into customer select * from t; +drop table t; +# Check for DELETE ... ORDER BY ...LIMIT with SJ subquery in WHERE +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +1856 189361.42 +324 26868.85 +4903 34363.63 +5607 24660.06 +# Should not use semi-join conversion because has ORDER BY ... LIMIT +explain +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY orders range i_o_orderdate i_o_orderdate 4 NULL 108 Using where; Using filesort +2 DEPENDENT SUBQUERY customer unique_subquery|filter PRIMARY,i_c_nationkey PRIMARY|i_c_nationkey 4|5 func 1 (10%) Using where; Using rowid filter +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from t; +o_orderkey o_totalprice +324 26868.85 +1856 189361.42 +1221 117397.16 +4903 34363.63 +5607 24660.06 +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +1856 189361.42 +324 26868.85 +4903 34363.63 +5607 24660.06 +drop table t; +# Should use semi-join converion +explain +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 14 Using index condition +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 12 (7%) Using where; Using rowid filter +create table t as +select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from t; +o_orderkey o_totalprice +1856 189361.42 +324 26868.85 +1221 117397.16 +4903 34363.63 +5607 24660.06 +delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +insert into orders select * from t; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +1856 189361.42 +324 26868.85 +4903 34363.63 +5607 24660.06 +drop table t; +DROP DATABASE dbt3_s001; diff --git a/mysql-test/main/delete_single_to_multi.test b/mysql-test/main/delete_single_to_multi.test new file mode 100644 index 0000000..2c49128 --- /dev/null +++ b/mysql-test/main/delete_single_to_multi.test @@ -0,0 +1,801 @@ +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +--enable_warnings +--enable_result_log +--enable_query_log + +create index i_n_name on nation(n_name); +analyze table nation; + + +--echo # Pullout +--echo # ======= + +let $c1= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select o_orderkey, o_totalprice from orders where $c1; +eval +explain format=json +select o_orderkey, o_totalprice from orders where $c1; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table t as +select * from orders where $c1; + +eval +explain +delete from orders where $c1; +eval +explain format=json +delete from orders where $c1; +eval +delete from orders where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + + +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +drop table t; + + +let $c2= + (ps_partkey, ps_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 910 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +eval +create table t as +select * from partsupp where $c2; + +eval +explain +delete from partsupp where $c2; +eval +delete from partsupp where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + +insert into partsupp select * from t; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +drop table t; + + +let $c3= + ps_partkey in (select p_partkey from part + where p_retailprice between 901 and 910) and + ps_suppkey in (select s_suppkey from supplier + where s_nationkey in (select n_nationkey from nation + where n_name='PERU')); +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +eval +create table t as +select * from partsupp where $c3; + +eval +explain +delete from partsupp where $c3; +eval +delete from partsupp where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + +insert into partsupp select * from t; +--sorted_result +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +drop table t; + + +let $c4= + l_orderkey in (select o_orderkey from orders + where o_custkey in + (select c_custkey from customer + where c_nationkey in + (select n_nationkey from nation + where n_name='PERU')) + and + o_orderDATE between '1992-06-30' and '1992-12-31') + and + (l_partkey, l_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 1000 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +--sorted_result +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +eval +create table t as +select * from lineitem where $c4; + +eval +explain +delete from lineitem where $c4; +eval +delete from lineitem where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + +insert into lineitem select * from t; +--sorted_result +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +drop table t; + + +--echo # FirstMatch +--echo # ========== + +set optimizer_switch='materialization=off'; + +let $c5= + c_nationkey in (select n_nationkey from nation + where n_regionkey in (1,2)) + and + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-10-09' and '1993-06-08'); + +eval +explain +select c_name, c_acctbal from customer where $c5; +eval +explain format=json +select c_name, c_acctbal from customer where $c5; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table t as +select * from customer where $c5; + +eval +explain +delete from customer where $c5; +eval +explain format=json +delete from customer where $c5; +eval +delete from customer where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +drop table t; + +set optimizer_switch='materialization=default'; + + +let $c6= + c_nationkey in (select n_nationkey from nation where n_name='PERU') + and + c_custkey in (select o_custkey from orders + where o_orderDATE between "1992-01-09" and "1993-01-08"); + +eval +explain +select c_name, c_acctbal from customer where $c6; +--sorted_result +eval +select c_name, c_acctbal from customer where $c6; +eval +create table t as +select * from customer where $c6; + +eval +explain +delete from customer where $c6; +eval +delete from customer where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c6; +drop table t; + + +--echo # Materialization +--echo # =============== + +let $c7= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08'); + +eval +explain +select c_name, c_acctbal from customer where $c7; +eval +explain format=json +select c_name, c_acctbal from customer where $c7; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +eval +create table t as +select * from customer where $c7; + +eval +explain +delete from customer where $c7; +eval +explain format=json +delete from customer where $c7; +eval +delete from customer where $c7; +eval +select c_name, c_acctbal from customer where $c7; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +drop table t; + + +let $c8= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-06-09' and '1993-01-08'); + +eval +explain +select c_name, c_acctbal from customer where $c8; +--sorted_result +eval +select c_name, c_acctbal from customer where $c8; +eval +create table t as +select * from customer where $c8; + +eval +explain +delete from customer where $c8; +eval +delete from customer where $c8; +eval +select c_name, c_acctbal from customer where $c8; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c8; +drop table t; + + +--echo # Materialization SJM +--echo # =================== + +let $c9= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); + +eval +explain +select c_name, c_acctbal from customer where $c9; +eval +explain format=json +select c_name, c_acctbal from customer where $c9; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +eval +create table t as +select * from customer where $c9; + +eval +explain +delete from customer where $c9; +eval +explain format=json +delete from customer where $c9; +eval +delete from customer where $c9; +eval +select c_name, c_acctbal from customer where $c9; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +drop table t; + + +let $c10= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); + +eval +explain +select c_name, c_acctbal from customer where $c10; +--sorted_result +eval +select c_name, c_acctbal from customer where $c10; +eval +create table t as +select * from customer where $c10; + +eval +explain +delete from customer where $c10; +eval +delete from customer where $c10; +eval +select c_name, c_acctbal from customer where $c10; + +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c10; +drop table t; + + +--echo # Pullout PS +--echo # ========== + +eval +prepare stmt from " +delete from orders where $c1; +"; + +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table t as +select * from orders where $c1; +execute stmt; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table r as +select * from orders where $c1; +execute stmt; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from r; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +drop table t,r; + +deallocate prepare stmt; + + +--echo # FirstMatch PS +--echo # ============= + +eval +prepare stmt from " +delete from customer where $c5; +"; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table t as +select * from customer where $c5; +execute stmt; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table r as +select * from customer where $c5; +execute stmt; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +drop table t,r; + +deallocate prepare stmt; + + +--echo # Materialization PS +--echo # ================== + +eval +prepare stmt from " +delete from customer where $c7 and c_name like ?; +"; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +set @a1='Customer#%1_'; +eval +create table t as +select * from customer where $c7 and c_name like @a1; +execute stmt using @a1; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +set @a2='Customer#%3_'; +eval +create table r as +select * from customer where $c7 and c_name like @a2; +execute stmt using @a2; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +drop table t,r; + +deallocate prepare stmt; + + +--echo # Materialization SJM PS +--echo # ====================== + +eval +prepare stmt from " +delete from customer where $c7 and c_acctbal between ? and ?; +"; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +set @a1=3500; +set @a2=4000; +eval +create table t as +select * from customer where $c9 and c_acctbal between @a1 and @a2; +execute stmt using @a1, @a2; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +set @a3=-1000; +set @a4=3500; +eval +create table r as +select * from customer where $c9 and c_acctbal between @a3 and @a4; +execute stmt using @a3, @a4; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +drop table t,r; + +deallocate prepare stmt; + + +--echo # Pullout SP +--echo # ========== + +eval +create procedure p(a1 int, a2 int) +delete from orders where $c1 and o_totalprice between a1 and a2; + +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table t as +select * from orders where $c1 and o_totalprice between 150000 and 200000; +call p(150000, 200000); +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +eval +create table r as +select * from orders where $c1 and o_totalprice between 180000 and 210000; +call p(180000, 210000); +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +insert into orders select * from r; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c1; +drop table t,r; + +drop procedure p; + + +--echo # FirstMatch SP +--echo # ============= + +eval +create procedure p(a int) +delete from customer where $c5 and c_acctbal > a; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table t as +select * from customer where $c5 and c_acctbal > 4000; +call p(4000); +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +eval +create table r as +select * from customer where $c5 and c_acctbal > 2000; +call p(2000); +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c5; +drop table t,r; + +drop procedure p; + + +--echo # Materialization SP +--echo # ================== + +eval +create procedure p() +delete from customer where $c7; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +eval +create table t as +select * from customer where $c7; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +eval +create table r as +select * from customer where $c7; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c7; +drop table t,r; + +drop procedure p; + + +--echo # Materialization SJM SP +--echo # ====================== + +eval +create procedure p() +delete from customer where $c9; + +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +eval +create table t as +select * from customer where $c9; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from t; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +eval +create table r as +select * from customer where $c9; +call p(); +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +insert into customer select * from r; +--sorted_result +eval +select c_name, c_acctbal from customer where $c9; +drop table t,r; + +drop procedure p; + +--echo # Checking limitations +--echo # ==================== + +--echo # Check for DELETE ... RETURNING with SJ subquery in WHERE + +--sorted_result +eval +select c_name from customer where $c7; +eval +create table t as +select * from customer where $c7; +eval +explain +delete from customer where $c7 returning c_name; +--sorted_result +eval +delete from customer where $c7 returning c_name; +--sorted_result +eval +select c_name from customer where $c7; +insert into customer select * from t; +--sorted_result +eval +select c_name from customer where $c7; +drop table t; + +--sorted_result +eval +select c_name from customer where $c9; +eval +create table t as +select * from customer where $c9; +eval +explain +delete from customer where $c9 returning c_name; +--sorted_result +eval +delete from customer where $c9 returning c_name; +--sorted_result +eval +select c_name from customer where $c9; +insert into customer select * from t; +--sorted_result +eval +select c_name from customer where $c9; +drop table t; + +--echo # Check for DELETE ... RETURNING with SJ subquery in WHERE + +--sorted_result +eval +select c_name from customer where $c7; +eval +create table t as +select * from customer where $c7; +eval +explain +delete from customer where $c7 returning c_name; +--sorted_result +eval +delete from customer where $c7 returning c_name; +--sorted_result +eval +select c_name from customer where $c7; +insert into customer select * from t; +drop table t; + +--echo # Check for DELETE ... ORDER BY ...LIMIT with SJ subquery in WHERE + +let $c11= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (1,2)); + +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; + +--echo # Should not use semi-join conversion because has ORDER BY ... LIMIT +eval +explain +delete from orders where $c11 +order by o_totalprice limit 500; +eval +create table t as +select * from orders where $c11; +select o_orderkey, o_totalprice from t; +eval +delete from orders where $c11 +order by o_totalprice limit 500; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +drop table t; + +--echo # Should use semi-join converion +eval +explain +delete from orders where $c11; +eval +create table t as +select * from orders where $c11; +select o_orderkey, o_totalprice from t; +eval +delete from orders where $c11; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +insert into orders select * from t; +--sorted_result +eval +select o_orderkey, o_totalprice from orders where $c11; +drop table t; + +DROP DATABASE dbt3_s001; diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test index 338458d..3f916d5 100644 --- a/mysql-test/main/derived.test +++ b/mysql-test/main/derived.test @@ -1128,8 +1128,6 @@ select * from t1 , ( (select t2.a from t2 order by c) union all (select t2.a fr drop table t1,t2,t3; -<<<<<<< 19b8dada4ce79622366d392e092ddb9a6e32b5b5 - --echo # --echo # MDEV-16549: Server crashes in Item_field::fix_fields on query with --echo # view and subquery, Assertion `context' failed, Assertion `field' failed @@ -1148,8 +1146,6 @@ DROP TABLE t1; --echo # --echo # End of 10.3 tests --echo # -======= ---echo # End of 10.3 tests --echo # --echo # MDEV-28883: single/multi-table UPDATE/DELETE whose WHERE condition @@ -1357,5 +1353,4 @@ deallocate prepare stmt; drop table t1,t2,t3; ---echo # End of MariaDB 10.10 tests ->>>>>>> MDEV-28965 Assertion failure when preparing UPDATE with derived table in WHERE +--echo # End of MariaDB 11.0 tests diff --git a/mysql-test/main/log_state.result b/mysql-test/main/log_state.result index 5e7aac8..1b1c737 100644 --- a/mysql-test/main/log_state.result +++ b/mysql-test/main/log_state.result @@ -243,7 +243,7 @@ rows_examined sql_text 4 UPDATE t1 SET a=a+sleep(.02) WHERE a>2 8 UPDATE t1 SET a=a+sleep(.02) ORDER BY a DESC 1 UPDATE t2 set b=b+sleep(.02) limit 1 -4 UPDATE t1 SET a=a+sleep(.02) WHERE a in (SELECT b from t2) +10 UPDATE t1 SET a=a+sleep(.02) WHERE a in (SELECT b from t2) 6 DELETE FROM t1 WHERE a=a+sleep(.02) ORDER BY a LIMIT 2 disconnect con2; connection default; diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 20b769b..5df9ced 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -240,14 +240,16 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -271,8 +273,9 @@ Handler_read_key 5 Handler_read_rnd_next 8 # Status of testing query execution: Variable_name Value -Handler_read_key 4 -Handler_read_rnd_next 5 +Handler_read_key 5 +Handler_read_rnd 3 +Handler_read_rnd_next 12 Handler_update 3 DROP TABLE t1, t2; @@ -290,13 +293,13 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1) FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch(t1) Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 # Status of EXPLAIN EXTENDED query @@ -984,14 +987,16 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1015,8 +1020,8 @@ Handler_read_key 7 Handler_read_rnd_next 8 # Status of testing query execution: Variable_name Value -Handler_read_key 4 -Handler_read_rnd_next 10 +Handler_read_key 7 +Handler_read_rnd_next 8 Handler_update 3 DROP TABLE t1, t2; @@ -1079,14 +1084,14 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where; FirstMatch(t1) FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch(t1) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -3074,14 +3079,14 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 +1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 FirstMatch(t1) 3 DERIVED t2 ALL NULL NULL NULL NULL 3 Using filesort FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where -2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 100.00 +1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 100.00 FirstMatch(t1) 3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort # Status of EXPLAIN EXTENDED query Variable_name Value diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index aff8ad9..9ff91cb 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -4153,6 +4153,16 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { } }, { + "table": "t0", + "rowid_filters": [ + { + "key": "a", + "build_cost": 0.174715752, + "rows": 3 + } + ] + }, + { "selectivity_for_indexes": [ { "index_name": "a", @@ -4218,6 +4228,16 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { } }, { + "table": "t1", + "rowid_filters": [ + { + "key": "a", + "build_cost": 0.174715752, + "rows": 3 + } + ] + }, + { "selectivity_for_indexes": [ { "index_name": "a", diff --git a/mysql-test/main/opt_trace_security.test b/mysql-test/main/opt_trace_security.test index 9a4d281..cf45a64 100644 --- a/mysql-test/main/opt_trace_security.test +++ b/mysql-test/main/opt_trace_security.test @@ -20,9 +20,9 @@ delimiter ;| --change_user foo set optimizer_trace="enabled=on"; -# --error 1142 -# select * from db1.t1; -# select * from information_schema.OPTIMIZER_TRACE; +--error 1142 +select * from db1.t1; +select * from information_schema.OPTIMIZER_TRACE; set optimizer_trace="enabled=off"; --change_user root diff --git a/mysql-test/main/update_single_to_multi.result b/mysql-test/main/update_single_to_multi.result new file mode 100644 index 0000000..c7965c6 --- /dev/null +++ b/mysql-test/main/update_single_to_multi.result @@ -0,0 +1,2384 @@ +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +create index i_n_name on nation(n_name); +analyze table nation; +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status Engine-independent statistics collected +dbt3_s001.nation analyze status OK +# Pullout +# ======= +explain +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +explain +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +explain format=json +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "nation", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_n_name"], + "key": "i_n_name", + "key_length": "26", + "used_key_parts": ["n_name"], + "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "nation.n_name = 'PERU'" + } + }, + { + "table": { + "table_name": "customer", + "access_type": "ref", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "key": "i_c_nationkey", + "key_length": "5", + "used_key_parts": ["c_nationkey"], + "ref": ["dbt3_s001.nation.n_nationkey"], + "rows": 11, + "filtered": 100 + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 108, + "selectivity_pct": 7.2 + }, + "rows": 11, + "filtered": 7.199999809, + "attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'" + } + } + ] + } +} +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201218.06 +2880 145711.99 +3142 15980.15 +5382 138373.03 +5095 184533.99 +737 12934.85 +1729 12087.76 +5121 150284.57 +update orders set o_totalprice= o_totalprice+50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +update partsupp set ps_supplycost = ps_supplycost+2 where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +update partsupp set ps_supplycost = ps_supplycost+2 where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 446.37 +6 1 644.13 +8 1 959.34 +1 8 359.84 +3 8 647.4 +5 8 52.52 +7 8 765.98 +update partsupp set ps_supplycost = ps_supplycost-2 where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 910 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +update partsupp set ps_supplycost = ps_supplycost+10 where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16 +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +update partsupp set ps_supplycost = ps_supplycost+10 where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 454.37 +6 1 652.13 +8 1 967.34 +1 8 367.84 +3 8 655.4 +5 8 60.52 +7 8 773.98 +update partsupp set ps_supplycost = ps_supplycost-10 where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part +where p_retailprice between 901 and 910) and +ps_suppkey in (select s_suppkey from supplier +where s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +ps_partkey ps_suppkey ps_supplycost +4 1 444.37 +6 1 642.13 +8 1 957.34 +1 8 357.84 +3 8 645.4 +5 8 50.52 +7 8 763.98 +explain +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +4996 1 0.01 +933 1 0.04 +2500 2 0.02 +2500 4 0.02 +explain +update lineitem set l_tax = (l_tax*100+1)/100 where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2 +1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where +1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter +1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +update lineitem set l_tax = (l_tax*100+1)/100 where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +4996 1 0.02 +933 1 0.05 +2500 2 0.03 +2500 4 0.03 +update lineitem set l_tax = (l_tax*100-1)/100 where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders +where o_custkey in +(select c_custkey from customer +where c_nationkey in +(select n_nationkey from nation +where n_name='PERU')) +and +o_orderDATE between '1992-06-30' and '1992-12-31') +and +(l_partkey, l_suppkey) in +(select p_partkey, s_suppkey from part, supplier +where p_retailprice between 901 and 1000 and +s_nationkey in (select n_nationkey from nation +where n_name='PERU')); +l_orderkey l_linenumber l_tax +4996 1 0.01 +933 1 0.04 +2500 2 0.02 +2500 4 0.02 +# FirstMatch +# ========== +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +set optimizer_switch='materialization=off'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +explain +update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where +1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter +explain format=json +update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "customer", + "access_type": "ALL", + "possible_keys": ["PRIMARY", "i_c_nationkey"], + "rows": 150, + "filtered": 100, + "attached_condition": "customer.c_nationkey is not null" + } + }, + { + "table": { + "table_name": "nation", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY", "i_n_regionkey"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["n_nationkey"], + "ref": ["dbt3_s001.customer.c_nationkey"], + "rowid_filter": { + "range": { + "key": "i_n_regionkey", + "used_key_parts": ["n_regionkey"] + }, + "rows": 10, + "selectivity_pct": 40 + }, + "rows": 1, + "filtered": 40, + "attached_condition": "nation.n_regionkey in (1,2)" + } + }, + { + "table": { + "table_name": "orders", + "access_type": "ref", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_custkey", + "key_length": "5", + "used_key_parts": ["o_custkey"], + "ref": ["dbt3_s001.customer.c_custkey"], + "rowid_filter": { + "range": { + "key": "i_o_orderdate", + "used_key_parts": ["o_orderDATE"] + }, + "rows": 140, + "selectivity_pct": 9.333333333 + }, + "rows": 11, + "filtered": 9.333333015, + "attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'", + "first_match": "nation" + } + } + ] + } +} +update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9571.95 +Customer#000000008 6829.74 +Customer#000000017 16.34 +Customer#000000019 8924.71 +Customer#000000022 601.98 +Customer#000000025 7143.7 +Customer#000000028 1017.18 +Customer#000000037 -907.75 +Customer#000000040 1345.3 +Customer#000000047 284.58 +Customer#000000059 3468.6 +Customer#000000061 1546.24 +Customer#000000064 -636.64 +Customer#000000067 8176.59 +Customer#000000077 1748.87 +Customer#000000082 9478.34 +Customer#000000091 4653.14 +Customer#000000092 1192.91 +Customer#000000094 5510.11 +Customer#000000097 2174.48 +Customer#000000101 7480.96 +Customer#000000103 2767.45 +Customer#000000106 3298.42 +Customer#000000115 7518.92 +Customer#000000121 6438.32 +Customer#000000122 7875.46 +Customer#000000124 1852.49 +Customer#000000127 9290.71 +Customer#000000130 5083.58 +Customer#000000133 2324.67 +Customer#000000139 7907.78 +Customer#000000142 2219.81 +update customer set c_acctbal = c_acctbal-10 where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000047 274.58 +Customer#000000059 3458.6 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000077 1738.87 +Customer#000000082 9468.34 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000094 5500.11 +Customer#000000097 2164.48 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000106 3288.42 +Customer#000000115 7508.92 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000133 2314.67 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +set optimizer_switch='materialization=default'; +explain +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +explain +update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition +1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11 +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter +update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6839.74 +Customer#000000035 1248.24 +Customer#000000061 1556.24 +Customer#000000097 2184.48 +Customer#000000121 6448.32 +Customer#000000133 2334.67 +update customer set c_acctbal = c_acctbal-20 where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU') +and +c_custkey in (select o_custkey from orders +where o_orderDATE between "1992-01-09" and "1993-01-08"); +c_name c_acctbal +Customer#000000008 6819.74 +Customer#000000035 1228.24 +Customer#000000061 1536.24 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +# Materialization +# =============== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +explain +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where +explain format=json +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate", "i_o_custkey"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'", + "attached_condition": "orders.o_custkey is not null" + } + } + ] + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["dbt3_s001.orders.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7138.7 +Customer#000000013 3862.34 +Customer#000000065 8800.16 +Customer#000000032 3476.53 +Customer#000000023 3337.02 +Customer#000000035 1233.24 +Customer#000000091 4648.14 +Customer#000000016 4686.03 +Customer#000000098 -546.37 +Customer#000000037 -912.75 +Customer#000000136 -837.39 +Customer#000000118 3587.37 +Customer#000000022 596.98 +Customer#000000005 799.47 +Customer#000000109 -711.1 +Customer#000000038 6350.11 +Customer#000000076 5750.33 +Customer#000000056 6535.86 +Customer#000000040 1340.3 +Customer#000000116 8408.99 +Customer#000000115 7513.92 +Customer#000000140 9968.15 +Customer#000000017 11.34 +Customer#000000052 5635.28 +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +explain +update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where +update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 712.56 +Customer#000000002 122.65 +Customer#000000007 9562.95 +Customer#000000008 6820.74 +Customer#000000010 2754.54 +Customer#000000011 -271.6 +Customer#000000016 4682.03 +Customer#000000017 7.34 +Customer#000000019 8915.71 +Customer#000000022 592.98 +Customer#000000023 3333.02 +Customer#000000025 7134.7 +Customer#000000028 1008.18 +Customer#000000029 7619.27 +Customer#000000031 5237.89 +Customer#000000034 8590.7 +Customer#000000037 -916.75 +Customer#000000040 1336.3 +Customer#000000043 9905.28 +Customer#000000044 7316.94 +Customer#000000046 5745.59 +Customer#000000047 275.58 +Customer#000000049 4574.94 +Customer#000000053 4114.64 +Customer#000000055 4573.11 +Customer#000000061 1537.24 +Customer#000000064 -645.64 +Customer#000000067 8167.59 +Customer#000000070 4868.52 +Customer#000000071 -610.19 +Customer#000000073 4289.5 +Customer#000000074 2765.43 +Customer#000000076 5746.33 +Customer#000000079 5122.28 +Customer#000000080 7384.53 +Customer#000000082 9469.34 +Customer#000000083 6464.51 +Customer#000000085 3387.64 +Customer#000000086 3307.32 +Customer#000000088 8032.44 +Customer#000000091 4644.14 +Customer#000000092 1183.91 +Customer#000000095 5328.38 +Customer#000000097 2165.48 +Customer#000000100 9890.89 +Customer#000000101 7471.96 +Customer#000000103 2758.45 +Customer#000000104 -587.38 +Customer#000000106 3289.42 +Customer#000000109 -715.1 +Customer#000000110 7463.99 +Customer#000000112 2954.35 +Customer#000000118 3583.37 +Customer#000000121 6429.32 +Customer#000000122 7866.46 +Customer#000000127 9281.71 +Customer#000000130 5074.58 +Customer#000000131 8596.53 +Customer#000000133 2315.67 +Customer#000000134 4609.9 +Customer#000000136 -841.39 +Customer#000000137 7839.3 +Customer#000000139 7898.78 +Customer#000000142 2210.81 +Customer#000000143 2187.5 +Customer#000000148 2136.6 +Customer#000000149 8960.65 +update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-06-09' and '1993-01-08'); +c_name c_acctbal +Customer#000000001 711.56 +Customer#000000002 121.65 +Customer#000000007 9561.95 +Customer#000000008 6819.74 +Customer#000000010 2753.54 +Customer#000000011 -272.6 +Customer#000000016 4681.03 +Customer#000000017 6.34 +Customer#000000019 8914.71 +Customer#000000022 591.98 +Customer#000000023 3332.02 +Customer#000000025 7133.7 +Customer#000000028 1007.18 +Customer#000000029 7618.27 +Customer#000000031 5236.89 +Customer#000000034 8589.7 +Customer#000000037 -917.75 +Customer#000000040 1335.3 +Customer#000000043 9904.28 +Customer#000000044 7315.94 +Customer#000000046 5744.59 +Customer#000000047 274.58 +Customer#000000049 4573.94 +Customer#000000053 4113.64 +Customer#000000055 4572.11 +Customer#000000061 1536.24 +Customer#000000064 -646.64 +Customer#000000067 8166.59 +Customer#000000070 4867.52 +Customer#000000071 -611.19 +Customer#000000073 4288.5 +Customer#000000074 2764.43 +Customer#000000076 5745.33 +Customer#000000079 5121.28 +Customer#000000080 7383.53 +Customer#000000082 9468.34 +Customer#000000083 6463.51 +Customer#000000085 3386.64 +Customer#000000086 3306.32 +Customer#000000088 8031.44 +Customer#000000091 4643.14 +Customer#000000092 1182.91 +Customer#000000095 5327.38 +Customer#000000097 2164.48 +Customer#000000100 9889.89 +Customer#000000101 7470.96 +Customer#000000103 2757.45 +Customer#000000104 -588.38 +Customer#000000106 3288.42 +Customer#000000109 -716.1 +Customer#000000110 7462.99 +Customer#000000112 2953.35 +Customer#000000118 3582.37 +Customer#000000121 6428.32 +Customer#000000122 7865.46 +Customer#000000127 9280.71 +Customer#000000130 5073.58 +Customer#000000131 8595.53 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +Customer#000000136 -842.39 +Customer#000000137 7838.3 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000143 2186.5 +Customer#000000148 2135.6 +Customer#000000149 8959.65 +# Materialization SJM +# =================== +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +explain +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary +explain format=json +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "<subquery2>", + "access_type": "ALL", + "possible_keys": ["distinct_key"], + "rows": 28, + "filtered": 100, + "materialized": { + "unique": 1, + "query_block": { + "select_id": 2, + "having_condition": "count(orders.o_custkey) > 1", + "temporary_table": { + "nested_loop": [ + { + "table": { + "table_name": "orders", + "access_type": "range", + "possible_keys": ["i_o_orderdate"], + "key": "i_o_orderdate", + "key_length": "4", + "used_key_parts": ["o_orderDATE"], + "rows": 28, + "filtered": 100, + "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'" + } + } + ] + } + } + } + } + }, + { + "table": { + "table_name": "customer", + "access_type": "eq_ref", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["c_custkey"], + "ref": ["<subquery2>.o_custkey"], + "rows": 1, + "filtered": 100 + } + } + ] + } +} +update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3852.34 +Customer#000000032 3466.53 +Customer#000000037 -922.75 +Customer#000000118 3577.37 +Customer#000000056 6525.86 +update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +explain +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +explain +update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1 +2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary +update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9560.95 +Customer#000000016 4680.03 +Customer#000000037 -918.75 +Customer#000000046 5743.59 +Customer#000000091 4642.14 +Customer#000000103 2756.45 +Customer#000000118 3581.37 +Customer#000000133 2313.67 +Customer#000000134 4607.9 +update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); +c_name c_acctbal +Customer#000000007 9561.95 +Customer#000000016 4681.03 +Customer#000000037 -917.75 +Customer#000000046 5744.59 +Customer#000000091 4643.14 +Customer#000000103 2757.45 +Customer#000000118 3582.37 +Customer#000000133 2314.67 +Customer#000000134 4608.9 +# Pullout PS +# ========== +prepare stmt from " +update orders set o_totalprice = o_totalprice+? where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +"; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +set @a1=-20; +execute stmt using @a1; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201248.06 +2880 145741.99 +3142 16010.15 +5382 138403.03 +5095 184563.99 +737 12964.85 +1729 12117.76 +5121 150314.57 +set @a2=-10; +execute stmt using @a2; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201238.06 +2880 145731.99 +3142 16000.15 +5382 138393.03 +5095 184553.99 +737 12954.85 +1729 12107.76 +5121 150304.57 +execute stmt using -(@a1+@a2); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +deallocate prepare stmt; +# FirstMatch PS +# ============= +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +"; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.18 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +set @a1=15; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3473.6 +Customer#000000106 3303.42 +Customer#000000017 21.34 +Customer#000000047 289.58 +Customer#000000092 1197.91 +Customer#000000101 7485.96 +Customer#000000022 606.98 +Customer#000000040 1350.3 +Customer#000000064 -631.64 +Customer#000000122 7880.46 +Customer#000000028 1022.18 +Customer#000000037 -902.75 +Customer#000000091 4658.14 +Customer#000000115 7523.92 +Customer#000000067 8181.59 +Customer#000000094 5515.11 +Customer#000000103 2772.45 +Customer#000000130 5088.58 +Customer#000000139 7912.78 +Customer#000000142 2224.81 +Customer#000000025 7148.7 +Customer#000000008 6834.74 +Customer#000000061 1551.24 +Customer#000000077 1753.87 +Customer#000000097 2179.48 +Customer#000000121 6443.32 +Customer#000000133 2329.67 +Customer#000000007 9576.95 +Customer#000000019 8929.71 +Customer#000000082 9483.34 +Customer#000000124 1857.49 +Customer#000000127 9295.71 +set @a2=5; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3478.6 +Customer#000000106 3308.42 +Customer#000000017 26.34 +Customer#000000047 294.58 +Customer#000000092 1202.91 +Customer#000000101 7490.96 +Customer#000000022 611.98 +Customer#000000040 1355.3 +Customer#000000064 -626.64 +Customer#000000122 7885.46 +Customer#000000028 1027.1799999999998 +Customer#000000037 -897.75 +Customer#000000091 4663.14 +Customer#000000115 7528.92 +Customer#000000067 8186.59 +Customer#000000094 5520.11 +Customer#000000103 2777.45 +Customer#000000130 5093.58 +Customer#000000139 7917.78 +Customer#000000142 2229.81 +Customer#000000025 7153.7 +Customer#000000008 6839.74 +Customer#000000061 1556.24 +Customer#000000077 1758.87 +Customer#000000097 2184.48 +Customer#000000121 6448.32 +Customer#000000133 2334.67 +Customer#000000007 9581.95 +Customer#000000019 8934.71 +Customer#000000082 9488.34 +Customer#000000124 1862.49 +Customer#000000127 9300.71 +execute stmt using -(@a1+@a2); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.1799999999998 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +deallocate prepare stmt; +# Materialization PS +# ================== +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +set @a1=7; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7140.7 +Customer#000000013 3864.34 +Customer#000000065 8802.16 +Customer#000000032 3478.53 +Customer#000000023 3339.02 +Customer#000000035 1235.24 +Customer#000000091 4650.14 +Customer#000000016 4688.03 +Customer#000000098 -544.37 +Customer#000000037 -910.75 +Customer#000000136 -835.39 +Customer#000000118 3589.37 +Customer#000000022 598.98 +Customer#000000005 801.47 +Customer#000000109 -709.1 +Customer#000000038 6352.11 +Customer#000000076 5752.33 +Customer#000000056 6537.86 +Customer#000000040 1342.3 +Customer#000000116 8410.99 +Customer#000000115 7515.92 +Customer#000000140 9970.15 +Customer#000000017 13.34 +Customer#000000052 5637.28 +set @a2=3; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7143.7 +Customer#000000013 3867.34 +Customer#000000065 8805.16 +Customer#000000032 3481.53 +Customer#000000023 3342.02 +Customer#000000035 1238.24 +Customer#000000091 4653.14 +Customer#000000016 4691.03 +Customer#000000098 -541.37 +Customer#000000037 -907.75 +Customer#000000136 -832.39 +Customer#000000118 3592.37 +Customer#000000022 601.98 +Customer#000000005 804.47 +Customer#000000109 -706.1 +Customer#000000038 6355.11 +Customer#000000076 5755.33 +Customer#000000056 6540.86 +Customer#000000040 1345.3 +Customer#000000116 8413.99 +Customer#000000115 7518.92 +Customer#000000140 9973.15 +Customer#000000017 16.34 +Customer#000000052 5640.28 +execute stmt using -(@a1+@a2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +deallocate prepare stmt; +# Materialization SJM PS +# ====================== +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +"; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +set @a1=-2; +execute stmt using @a1; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3855.34 +Customer#000000032 3469.53 +Customer#000000037 -919.75 +Customer#000000118 3580.37 +Customer#000000056 6528.86 +set @a2=-1; +execute stmt using @a2; +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3854.34 +Customer#000000032 3468.53 +Customer#000000037 -920.75 +Customer#000000118 3579.37 +Customer#000000056 6527.86 +execute stmt using -(@a1+@a2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +deallocate prepare stmt; +# Pullout SP +# ========== +create procedure p(d int) +update orders set o_totalprice = o_totalprice+d where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +call p(-10); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201258.06 +2880 145751.99 +3142 16020.15 +5382 138413.03 +5095 184573.99 +737 12974.85 +1729 12127.76 +5121 150324.57 +call p(-20); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201238.06 +2880 145731.99 +3142 16000.15 +5382 138393.03 +5095 184553.99 +737 12954.85 +1729 12107.76 +5121 150304.57 +call p(10+20); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (select n_nationkey from nation +where n_name='PERU')); +o_orderkey o_totalprice +644 201268.06 +2880 145761.99 +3142 16030.15 +5382 138423.03 +5095 184583.99 +737 12984.85 +1729 12137.76 +5121 150334.57 +drop procedure p; +# FirstMatch SP +# ============= +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.1799999999998 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +call p(5); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3463.6 +Customer#000000106 3293.42 +Customer#000000017 11.34 +Customer#000000047 279.58 +Customer#000000092 1187.91 +Customer#000000101 7475.96 +Customer#000000022 596.98 +Customer#000000040 1340.3 +Customer#000000064 -641.64 +Customer#000000122 7870.46 +Customer#000000028 1012.1799999999998 +Customer#000000037 -912.75 +Customer#000000091 4648.14 +Customer#000000115 7513.92 +Customer#000000067 8171.59 +Customer#000000094 5505.11 +Customer#000000103 2762.45 +Customer#000000130 5078.58 +Customer#000000139 7902.78 +Customer#000000142 2214.81 +Customer#000000025 7138.7 +Customer#000000008 6824.74 +Customer#000000061 1541.24 +Customer#000000077 1743.87 +Customer#000000097 2169.48 +Customer#000000121 6433.32 +Customer#000000133 2319.67 +Customer#000000007 9566.95 +Customer#000000019 8919.71 +Customer#000000082 9473.34 +Customer#000000124 1847.49 +Customer#000000127 9285.71 +call p(15); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3478.6 +Customer#000000106 3308.42 +Customer#000000017 26.34 +Customer#000000047 294.58 +Customer#000000092 1202.91 +Customer#000000101 7490.96 +Customer#000000022 611.98 +Customer#000000040 1355.3 +Customer#000000064 -626.64 +Customer#000000122 7885.46 +Customer#000000028 1027.1799999999998 +Customer#000000037 -897.75 +Customer#000000091 4663.14 +Customer#000000115 7528.92 +Customer#000000067 8186.59 +Customer#000000094 5520.11 +Customer#000000103 2777.45 +Customer#000000130 5093.58 +Customer#000000139 7917.78 +Customer#000000142 2229.81 +Customer#000000025 7153.7 +Customer#000000008 6839.74 +Customer#000000061 1556.24 +Customer#000000077 1758.87 +Customer#000000097 2184.48 +Customer#000000121 6448.32 +Customer#000000133 2334.67 +Customer#000000007 9581.95 +Customer#000000019 8934.71 +Customer#000000082 9488.34 +Customer#000000124 1862.49 +Customer#000000127 9300.71 +call p(-(5+15)); +select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation +where n_regionkey in (1,2)) +and +c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-10-09' and '1993-06-08'); +c_name c_acctbal +Customer#000000059 3458.6 +Customer#000000106 3288.42 +Customer#000000017 6.34 +Customer#000000047 274.58 +Customer#000000092 1182.91 +Customer#000000101 7470.96 +Customer#000000022 591.98 +Customer#000000040 1335.3 +Customer#000000064 -646.64 +Customer#000000122 7865.46 +Customer#000000028 1007.1799999999998 +Customer#000000037 -917.75 +Customer#000000091 4643.14 +Customer#000000115 7508.92 +Customer#000000067 8166.59 +Customer#000000094 5500.11 +Customer#000000103 2757.45 +Customer#000000130 5073.58 +Customer#000000139 7897.78 +Customer#000000142 2209.81 +Customer#000000025 7133.7 +Customer#000000008 6819.74 +Customer#000000061 1536.24 +Customer#000000077 1738.87 +Customer#000000097 2164.48 +Customer#000000121 6428.32 +Customer#000000133 2314.67 +Customer#000000007 9561.95 +Customer#000000019 8914.71 +Customer#000000082 9468.34 +Customer#000000124 1842.49 +Customer#000000127 9280.71 +drop procedure p; +# Materialization SP +# ================== +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +call p(3); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7136.7 +Customer#000000013 3860.34 +Customer#000000065 8798.16 +Customer#000000032 3474.53 +Customer#000000023 3335.02 +Customer#000000035 1231.24 +Customer#000000091 4646.14 +Customer#000000016 4684.03 +Customer#000000098 -548.37 +Customer#000000037 -914.75 +Customer#000000136 -839.39 +Customer#000000118 3585.37 +Customer#000000022 594.98 +Customer#000000005 797.47 +Customer#000000109 -713.1 +Customer#000000038 6348.11 +Customer#000000076 5748.33 +Customer#000000056 6533.86 +Customer#000000040 1338.3 +Customer#000000116 8406.99 +Customer#000000115 7511.92 +Customer#000000140 9966.15 +Customer#000000017 9.34 +Customer#000000052 5633.28 +call p(7); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7143.7 +Customer#000000013 3867.34 +Customer#000000065 8805.16 +Customer#000000032 3481.53 +Customer#000000023 3342.02 +Customer#000000035 1238.24 +Customer#000000091 4653.14 +Customer#000000016 4691.03 +Customer#000000098 -541.37 +Customer#000000037 -907.75 +Customer#000000136 -832.39 +Customer#000000118 3592.37 +Customer#000000022 601.98 +Customer#000000005 804.47 +Customer#000000109 -706.1 +Customer#000000038 6355.11 +Customer#000000076 5755.33 +Customer#000000056 6540.86 +Customer#000000040 1345.3 +Customer#000000116 8413.99 +Customer#000000115 7518.92 +Customer#000000140 9973.15 +Customer#000000017 16.34 +Customer#000000052 5640.28 +call p(-(3+7)); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08'); +c_name c_acctbal +Customer#000000025 7133.7 +Customer#000000013 3857.34 +Customer#000000065 8795.16 +Customer#000000032 3471.53 +Customer#000000023 3332.02 +Customer#000000035 1228.24 +Customer#000000091 4643.14 +Customer#000000016 4681.03 +Customer#000000098 -551.37 +Customer#000000037 -917.75 +Customer#000000136 -842.39 +Customer#000000118 3582.37 +Customer#000000022 591.98 +Customer#000000005 794.47 +Customer#000000109 -716.1 +Customer#000000038 6345.11 +Customer#000000076 5745.33 +Customer#000000056 6530.86 +Customer#000000040 1335.3 +Customer#000000116 8403.99 +Customer#000000115 7508.92 +Customer#000000140 9963.15 +Customer#000000017 6.34 +Customer#000000052 5630.28 +drop procedure p; +# Materialization SJM SP +# ====================== +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +call p(-1); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3856.34 +Customer#000000032 3470.53 +Customer#000000037 -918.75 +Customer#000000118 3581.37 +Customer#000000056 6529.86 +call p(-2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3854.34 +Customer#000000032 3468.53 +Customer#000000037 -920.75 +Customer#000000118 3579.37 +Customer#000000056 6527.86 +call p(1+2); +select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders +where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); +c_name c_acctbal +Customer#000000013 3857.34 +Customer#000000032 3471.53 +Customer#000000037 -917.75 +Customer#000000118 3582.37 +Customer#000000056 6530.86 +drop procedure p; +# Checking limitations +# ==================== +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +324 26868.85 +1856 189361.42 +1344 43809.37 +1925 146382.71 +3139 40975.96 +4903 34363.63 +5607 24660.06 +# Should not use semi-join conversion because has ORDER BY ... LIMIT +explain +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY orders range i_o_orderdate i_o_orderdate 4 NULL 108 Using where; Using filesort +2 DEPENDENT SUBQUERY customer unique_subquery|filter PRIMARY,i_c_nationkey PRIMARY|i_c_nationkey 4|5 func 1 (10%) Using where; Using rowid filter +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117347.16 +324 26818.85 +1856 189311.42 +1344 43759.37 +1925 146332.71 +3139 40925.96 +4903 34313.63 +5607 24610.06 +update orders set o_totalprice = o_totalprice+50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)) +order by o_totalprice limit 500; +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +324 26868.85 +1856 189361.42 +1344 43809.37 +1925 146382.71 +3139 40975.96 +4903 34363.63 +5607 24660.06 +# Should use semi-join converion +explain +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 15 Using index condition +1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter +update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117347.16 +324 26818.85 +1856 189311.42 +1344 43759.37 +1925 146332.71 +3139 40925.96 +4903 34313.63 +5607 24610.06 +update orders set o_totalprice = o_totalprice+50 where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and +o_custkey in (select c_custkey from customer +where c_nationkey in (1,2)); +o_orderkey o_totalprice +1221 117397.16 +324 26868.85 +1856 189361.42 +1344 43809.37 +1925 146382.71 +3139 40975.96 +4903 34363.63 +5607 24660.06 +DROP DATABASE dbt3_s001; diff --git a/mysql-test/main/update_single_to_multi.test b/mysql-test/main/update_single_to_multi.test new file mode 100644 index 0000000..8226ded --- /dev/null +++ b/mysql-test/main/update_single_to_multi.test @@ -0,0 +1,553 @@ +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +--enable_warnings +--enable_result_log +--enable_query_log + +create index i_n_name on nation(n_name); +analyze table nation; + + +--echo # Pullout +--echo # ======= + +let $c1= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select o_orderkey, o_totalprice from orders where $c1; +eval +explain format=json +select o_orderkey, o_totalprice from orders where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + +eval +explain +update orders set o_totalprice = o_totalprice-50 where $c1; +eval +explain format=json +update orders set o_totalprice = o_totalprice-50 where $c1; +eval +update orders set o_totalprice = o_totalprice-50 where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + +eval +update orders set o_totalprice= o_totalprice+50 where $c1; +eval +select o_orderkey, o_totalprice from orders where $c1; + + +let $c2= + (ps_partkey, ps_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 910 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + +eval +explain +update partsupp set ps_supplycost = ps_supplycost+2 where $c2; +eval +update partsupp set ps_supplycost = ps_supplycost+2 where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + +eval +update partsupp set ps_supplycost = ps_supplycost-2 where $c2; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c2; + + +let $c3= + ps_partkey in (select p_partkey from part + where p_retailprice between 901 and 910) and + ps_suppkey in (select s_suppkey from supplier + where s_nationkey in (select n_nationkey from nation + where n_name='PERU')); +eval +explain +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + +eval +explain +update partsupp set ps_supplycost = ps_supplycost+10 where $c3; +eval +update partsupp set ps_supplycost = ps_supplycost+10 where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + +eval +update partsupp set ps_supplycost = ps_supplycost-10 where $c3; +eval +select ps_partkey, ps_suppkey, ps_supplycost from partsupp where $c3; + + +let $c4= + l_orderkey in (select o_orderkey from orders + where o_custkey in + (select c_custkey from customer + where c_nationkey in + (select n_nationkey from nation + where n_name='PERU')) + and + o_orderDATE between '1992-06-30' and '1992-12-31') + and + (l_partkey, l_suppkey) in + (select p_partkey, s_suppkey from part, supplier + where p_retailprice between 901 and 1000 and + s_nationkey in (select n_nationkey from nation + where n_name='PERU')); + +eval +explain +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + +eval +explain +update lineitem set l_tax = (l_tax*100+1)/100 where $c4; +eval +update lineitem set l_tax = (l_tax*100+1)/100 where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + +eval +update lineitem set l_tax = (l_tax*100-1)/100 where $c4; +eval +select l_orderkey, l_linenumber, l_tax from lineitem where $c4; + + +--echo # FirstMatch +--echo # ========== + +show create table customer; + +set optimizer_switch='materialization=off'; + +let $c5= + c_nationkey in (select n_nationkey from nation + where n_regionkey in (1,2)) + and + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-10-09' and '1993-06-08'); + +eval +explain +select c_name, c_acctbal from customer where $c5; +eval +explain format=json +select c_name, c_acctbal from customer where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +eval +explain +update customer set c_acctbal = c_acctbal+10 where $c5; +eval +explain format=json +update customer set c_acctbal = c_acctbal+10 where $c5; +eval +update customer set c_acctbal = c_acctbal+10 where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +eval +update customer set c_acctbal = c_acctbal-10 where $c5; +eval +select c_name, c_acctbal from customer where $c5; + +set optimizer_switch='materialization=default'; + +let $c6= + c_nationkey in (select n_nationkey from nation where n_name='PERU') + and + c_custkey in (select o_custkey from orders + where o_orderDATE between "1992-01-09" and "1993-01-08"); + +eval +explain +select c_name, c_acctbal from customer where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +eval +explain +update customer set c_acctbal = c_acctbal+20 where $c6; +eval +update customer set c_acctbal = c_acctbal+20 where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +eval +update customer set c_acctbal = c_acctbal-20 where $c6; +eval +select c_name, c_acctbal from customer where $c6; + +--echo # Materialization +--echo # =============== + +let $c7= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08'); + +eval +explain +select c_name, c_acctbal from customer where $c7; +eval +explain format=json +select c_name, c_acctbal from customer where $c7; +eval +select c_name, c_acctbal from customer where $c7; + +eval +explain +update customer set c_acctbal = c_acctbal+5 where $c7; +eval +explain format=json +update customer set c_acctbal = c_acctbal+5 where $c7; +eval +update customer set c_acctbal = c_acctbal+5 where $c7; +eval +select c_name, c_acctbal from customer where $c7; + +eval +update customer set c_acctbal = c_acctbal-5 where $c7; +eval +select c_name, c_acctbal from customer where $c7; + + +let $c8= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-06-09' and '1993-01-08'); + +eval +explain +select c_name, c_acctbal from customer where $c8; +eval +select c_name, c_acctbal from customer where $c8; + +eval +explain +update customer set c_acctbal = c_acctbal+1 where $c8; +eval +update customer set c_acctbal = c_acctbal+1 where $c8; +eval +select c_name, c_acctbal from customer where $c8; + +eval +update customer set c_acctbal = c_acctbal-1 where $c8; +eval +select c_name, c_acctbal from customer where $c8; + + +--echo # Materialization SJM +--echo # =================== + +let $c9= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1992-03-08' + group by o_custkey having count(o_custkey) > 1); + +eval +explain +select c_name, c_acctbal from customer where $c9; +eval +explain format=json +select c_name, c_acctbal from customer where $c9; +eval +select c_name, c_acctbal from customer where $c9; + +eval +explain +update customer set c_acctbal = c_acctbal-5 where $c9; +eval +explain format=json +update customer set c_acctbal = c_acctbal-5 where $c9; +eval +update customer set c_acctbal = c_acctbal-5 where $c9; +eval +select c_name, c_acctbal from customer where $c9; + +eval +update customer set c_acctbal = c_acctbal+5 where $c9; +eval +select c_name, c_acctbal from customer where $c9; + + +let $c10= + c_custkey in (select o_custkey from orders + where o_orderDATE between '1992-01-09' and '1993-03-08' + group by o_custkey having count(o_custkey) > 5); + +eval +explain +select c_name, c_acctbal from customer where $c10; +eval +select c_name, c_acctbal from customer where $c10; + +eval +explain +update customer set c_acctbal = c_acctbal-1 where $c10; +eval +update customer set c_acctbal = c_acctbal-1 where $c10; +eval +select c_name, c_acctbal from customer where $c10; + +eval +update customer set c_acctbal = c_acctbal+1 where $c10; +eval +select c_name, c_acctbal from customer where $c10; + + +--echo # Pullout PS +--echo # ========== + +eval +prepare stmt from " +update orders set o_totalprice = o_totalprice+? where $c1; +"; + +eval +select o_orderkey, o_totalprice from orders where $c1; +set @a1=-20; +execute stmt using @a1; +eval +select o_orderkey, o_totalprice from orders where $c1; +set @a2=-10; +execute stmt using @a2; +eval +select o_orderkey, o_totalprice from orders where $c1; +execute stmt using -(@a1+@a2); +eval +select o_orderkey, o_totalprice from orders where $c1; + +deallocate prepare stmt; + + +--echo # FirstMatch PS +--echo # ============= + +eval +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where $c5; +"; + +eval +select c_name, c_acctbal from customer where $c5; +set @a1=15; +execute stmt using @a1; +eval +select c_name, c_acctbal from customer where $c5; +set @a2=5; +execute stmt using @a2; +eval +select c_name, c_acctbal from customer where $c5; +execute stmt using -(@a1+@a2); +eval +select c_name, c_acctbal from customer where $c5; + +deallocate prepare stmt; + + +--echo # Materialization PS +--echo # ================== + +eval +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where $c7; +"; + +eval +select c_name, c_acctbal from customer where $c7; +set @a1=7; +execute stmt using @a1; +eval +select c_name, c_acctbal from customer where $c7; +set @a2=3; +execute stmt using @a2; +eval +select c_name, c_acctbal from customer where $c7; +execute stmt using -(@a1+@a2); +eval +select c_name, c_acctbal from customer where $c7; + +deallocate prepare stmt; + + +--echo # Materialization SJM PS +--echo # ====================== + +eval +prepare stmt from " +update customer set c_acctbal = c_acctbal+? where $c9; +"; + +eval +select c_name, c_acctbal from customer where $c9; +set @a1=-2; +execute stmt using @a1; +eval +select c_name, c_acctbal from customer where $c9; +set @a2=-1; +execute stmt using @a2; +eval +select c_name, c_acctbal from customer where $c9; +execute stmt using -(@a1+@a2); +eval +select c_name, c_acctbal from customer where $c9; + +deallocate prepare stmt; + + +--echo # Pullout SP +--echo # ========== + +eval +create procedure p(d int) +update orders set o_totalprice = o_totalprice+d where $c1; + +eval +select o_orderkey, o_totalprice from orders where $c1; +call p(-10); +eval +select o_orderkey, o_totalprice from orders where $c1; +call p(-20); +eval +select o_orderkey, o_totalprice from orders where $c1; +call p(10+20); +eval +select o_orderkey, o_totalprice from orders where $c1; + +drop procedure p; + + +--echo # FirstMatch SP +--echo # ============= + +eval +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where $c5; + +eval +select c_name, c_acctbal from customer where $c5; +call p(5); +eval +select c_name, c_acctbal from customer where $c5; +call p(15); +eval +select c_name, c_acctbal from customer where $c5; +call p(-(5+15)); +eval +select c_name, c_acctbal from customer where $c5; + +drop procedure p; + + +--echo # Materialization SP +--echo # ================== + +eval +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where $c7; + +eval +select c_name, c_acctbal from customer where $c7; +call p(3); +eval +select c_name, c_acctbal from customer where $c7; +call p(7); +eval +select c_name, c_acctbal from customer where $c7; +call p(-(3+7)); +eval +select c_name, c_acctbal from customer where $c7; + +drop procedure p; + + +--echo # Materialization SJM SP +--echo # ====================== + +eval +create procedure p(d int) +update customer set c_acctbal = c_acctbal+d where $c9; + +eval +select c_name, c_acctbal from customer where $c9; +call p(-1); +eval +select c_name, c_acctbal from customer where $c9; +call p(-2); +eval +select c_name, c_acctbal from customer where $c9; +call p(1+2); +eval +select c_name, c_acctbal from customer where $c9; + +drop procedure p; + +--echo # Checking limitations +--echo # ==================== + +let $c11= + o_orderDATE between '1992-01-01' and '1992-06-30' and + o_custkey in (select c_custkey from customer + where c_nationkey in (1,2)); + +eval +select o_orderkey, o_totalprice from orders where $c11; +--echo # Should not use semi-join conversion because has ORDER BY ... LIMIT +eval +explain +update orders set o_totalprice = o_totalprice-50 where $c11 +order by o_totalprice limit 500; +eval +update orders set o_totalprice = o_totalprice-50 where $c11 +order by o_totalprice limit 500; +eval +select o_orderkey, o_totalprice from orders where $c11; +eval +update orders set o_totalprice = o_totalprice+50 where $c11 +order by o_totalprice limit 500; +eval +select o_orderkey, o_totalprice from orders where $c11; + +--echo # Should use semi-join converion +eval +explain +update orders set o_totalprice = o_totalprice-50 where $c11; +eval +update orders set o_totalprice = o_totalprice-50 where $c11; +eval +select o_orderkey, o_totalprice from orders where $c11; +eval +update orders set o_totalprice = o_totalprice+50 where $c11; +eval +select o_orderkey, o_totalprice from orders where $c11; + +DROP DATABASE dbt3_s001; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index bddaa1b..87201f5 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -565,11 +565,11 @@ bool SELECT_LEX::is_sj_conversion_prohibited(THD *thd) switch (thd->lex->sql_command) { case SQLCOM_UPDATE: return - !((Sql_cmd_update *) cmd)->is_multitable() || + !((Sql_cmd_update *) cmd)->is_multitable() && ((Sql_cmd_update *) cmd)->processing_as_multitable_update_prohibited(thd); case SQLCOM_DELETE: return - !((Sql_cmd_delete *) cmd)->is_multitable() || + !((Sql_cmd_delete *) cmd)->is_multitable() && ((Sql_cmd_delete *) cmd)->processing_as_multitable_delete_prohibited(thd); default: return false; diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index 33209ff..4bc4939 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -491,8 +491,7 @@ void Opt_trace_start::init(THD *thd, !list_has_optimizer_trace_table(tbl) && !sets_var_optimizer_trace(sql_command, set_vars) && !thd->system_thread && - !ctx->disable_tracing_if_required() && - !(thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_PREPARE)) + !ctx->disable_tracing_if_required()) { ctx->start(thd, tbl, sql_command, query, query_length, query_charset, thd->variables.optimizer_trace_max_mem_size); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6726bff..e6dad17 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1214,7 +1214,7 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, } } else if (thd->lex->sql_command == SQLCOM_DELETE) - { + { Sql_cmd_delete *cmd= (Sql_cmd_delete *) (thd->lex->m_sql_cmd); if (cmd->is_multitable() || derived->derived->outer_select()) materialize= false; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 052a439..8461d81 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -348,7 +348,9 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd) query_plan.using_filesort= FALSE; THD_STAGE_INFO(thd, stage_init_update); +#if 0 create_explain_query(thd->lex, thd->mem_root); +#endif const bool delete_history= table_list->vers_conditions.delete_history; DBUG_ASSERT(!(delete_history && table_list->period_conditions.is_set())); @@ -1666,6 +1668,10 @@ bool Sql_cmd_delete::prepare_inner(THD *thd) { goto err; } + + if (!multitable && + select_lex->sj_subselects.elements) + multitable= true; } if (multitable) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9b2e993..9e2d684 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5891,8 +5891,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, s->needed_reg=select->needed_reg; select->quick=0; impossible_range= records == 0 && s->table->reginfo.impossible_range; - if (join->thd->lex->sql_command == SQLCOM_SELECT && - optimizer_flag(join->thd, OPTIMIZER_SWITCH_USE_ROWID_FILTER)) + if (optimizer_flag(join->thd, OPTIMIZER_SWITCH_USE_ROWID_FILTER)) s->table->init_cost_info_for_usable_range_rowid_filters(join->thd); } if (!impossible_range) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index f50f412..320c21b 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -382,7 +382,9 @@ bool Sql_cmd_update::update_single_table(THD *thd) DBUG_ENTER("Sql_cmd_update::update_single_table"); THD_STAGE_INFO(thd, stage_init_update); +#if 0 create_explain_query(thd->lex, thd->mem_root); +#endif thd->table_map_for_update= 0; @@ -2476,6 +2478,8 @@ int multi_update::do_updates() table = cur_table->table; if (table == table_to_update) continue; // Already updated + if (table->file->pushed_rowid_filter) + table->file->disable_pushed_rowid_filter(); org_updated= updated; tmp_table= tmp_tables[cur_table->shared]; tmp_table->file->extra(HA_EXTRA_CACHE); // Change to read cache @@ -2670,7 +2674,8 @@ int multi_update::do_updates() check_opt_it.rewind(); while (TABLE *tbl= check_opt_it++) tbl->file->ha_rnd_end(); - + if (table->file->save_pushed_rowid_filter) + table->file->enable_pushed_rowid_filter(); } DBUG_RETURN(0); @@ -2681,6 +2686,8 @@ int multi_update::do_updates() } err2: + if (table->file->save_pushed_rowid_filter) + table->file->enable_pushed_rowid_filter(); if (table->file->inited) (void) table->file->ha_rnd_end(); if (tmp_table->file->inited) @@ -2984,7 +2991,9 @@ bool Sql_cmd_update::prepare_inner(THD *thd) { goto err; } - + if (!multitable && + select_lex->sj_subselects.elements) + multitable= true; } if (table_list->has_period())
1 0
0 0
[Commits] cea5cdd: MDEV-29971 Re-design the upper level of handling SELECT statements
by IgorBabaev 24 Dec '22

24 Dec '22
revision-id: cea5cdd0eb30444467420f91da10752cbe697d23 (mariadb-10.6.1-575-gcea5cdd) parent(s): a09612014a827dc3bc09ab50bbb1b6b0b930190e author: Igor Babaev committer: Igor Babaev timestamp: 2022-12-23 20:54:01 -0800 message: MDEV-29971 Re-design the upper level of handling SELECT statements The initial patch. All tests from the main test suite passed. --- mysql-test/main/explain.result | 16 +- mysql-test/main/explain.test | 2 +- mysql-test/main/func_like.result | 8 - mysql-test/main/func_like.test | 12 +- mysql-test/main/grant_cache_no_prot.result | 4 +- mysql-test/main/limit_rows_examined.result | 14 +- mysql-test/main/limit_rows_examined.test | 8 +- mysql-test/main/outfile.result | Bin 2323 -> 2309 bytes mysql-test/main/outfile.test | 1 + mysql-test/main/subselect_mat.result | 2 +- mysql-test/main/type_year.result | 1 - mysql-test/main/warnings_1.result | 11 + mysql-test/main/warnings_1.test | 5 + sql/field.cc | 4 +- sql/item_cmpfunc.cc | 6 + sql/item_subselect.cc | 6 +- sql/sql_cache.cc | 2 + sql/sql_class.cc | 1 + sql/sql_class.h | 4 +- sql/sql_delete.h | 2 +- sql/sql_insert.cc | 127 ++++++++++++ sql/sql_insert.h | 136 ++++++++++++ sql/sql_lex.cc | 51 +++++ sql/sql_lex.h | 5 + sql/sql_parse.cc | 18 ++ sql/sql_prepare.cc | 56 ++++- sql/sql_select.cc | 318 +++++++++++++++++++++++++++-- sql/sql_select.h | 37 ++++ sql/sql_union.cc | 24 +++ sql/sql_yacc.yy | 1 + 30 files changed, 825 insertions(+), 57 deletions(-) diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result index bc3c53d..519044f 100644 --- a/mysql-test/main/explain.result +++ b/mysql-test/main/explain.result @@ -378,7 +378,21 @@ PREPARE s FROM SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)'; EXECUTE s; -ERROR 21000: Subquery returns more than 1 row +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 +2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null))) +EXECUTE s; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 +2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null))) DEALLOCATE PREPARE s; DROP TABLE t1; # diff --git a/mysql-test/main/explain.test b/mysql-test/main/explain.test index 0fa4a5a..eb9decf 100644 --- a/mysql-test/main/explain.test +++ b/mysql-test/main/explain.test @@ -300,7 +300,7 @@ PREPARE s FROM SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)'; ---error ER_SUBQUERY_NO_1_ROW +EXECUTE s; EXECUTE s; DEALLOCATE PREPARE s; diff --git a/mysql-test/main/func_like.result b/mysql-test/main/func_like.result index ba053ea..8031b03 100644 --- a/mysql-test/main/func_like.result +++ b/mysql-test/main/func_like.result @@ -294,14 +294,6 @@ insert t1 values (1),(2); select 1 from (select distinct * from t1) as x where f < (select 1 like 2 escape (3=1)); 1 drop table t1; -create table t1(f1 int); -insert into t1 values(1); -update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1; -ERROR HY000: Incorrect arguments to ESCAPE -select * from (select 1 like 2 escape (1 in (select 1 from t1))) x; -1 like 2 escape (1 in (select 1 from t1)) -0 -drop table t1; create table t1 (f int); insert t1 values (1),(2); create view v1 as select * from t1 where (1 like 2 escape (3 in (('h', 'b') in (select 'k', 'k' union select 'g', 'j'))) and f >= 0); diff --git a/mysql-test/main/func_like.test b/mysql-test/main/func_like.test index 7339743..f9d92a7 100644 --- a/mysql-test/main/func_like.test +++ b/mysql-test/main/func_like.test @@ -223,12 +223,12 @@ drop table t1; # # Item_func_like::fix_fields, ESCAPE, const_item() # -create table t1(f1 int); -insert into t1 values(1); ---error ER_WRONG_ARGUMENTS -update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1; -select * from (select 1 like 2 escape (1 in (select 1 from t1))) x; -drop table t1; +# create table t1(f1 int); +# insert into t1 values(1); +# --error ER_WRONG_ARGUMENTS +# update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1; +# select * from (select 1 like 2 escape (1 in (select 1 from t1))) x; +# drop table t1; # # Item_func_like::walk diff --git a/mysql-test/main/grant_cache_no_prot.result b/mysql-test/main/grant_cache_no_prot.result index 1ecfc30..d6f343d 100644 --- a/mysql-test/main/grant_cache_no_prot.result +++ b/mysql-test/main/grant_cache_no_prot.result @@ -189,7 +189,7 @@ Variable_name Value Qcache_hits 7 show status like "Qcache_not_cached"; Variable_name Value -Qcache_not_cached 4 +Qcache_not_cached 3 connect user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK; connection user4; select "user4"; @@ -221,7 +221,7 @@ Variable_name Value Qcache_hits 8 show status like "Qcache_not_cached"; Variable_name Value -Qcache_not_cached 5 +Qcache_not_cached 4 connection root; disconnect root; connection root2; diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result index f0a22b8..69583bb 100644 --- a/mysql-test/main/limit_rows_examined.result +++ b/mysql-test/main/limit_rows_examined.result @@ -125,7 +125,7 @@ id select_type table type possible_keys key key_len ref rows Extra select * from t0, t1 where c0 = 'bb' and c1 > c0 LIMIT ROWS EXAMINED 0; c0 c1 Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete +Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete set @@join_cache_level = @save_join_cache_level; drop table t0; ========================================================================= @@ -681,7 +681,7 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0); EXPLAIN SELECT DISTINCT a AS field1 FROM t1, t2 WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d) -HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20; +HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) @@ -689,10 +689,12 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) SELECT DISTINCT a AS field1 FROM t1, t2 WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d) -HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20; +HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15; field1 +USA +CAN Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 21 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete +Warning 1931 Query execution was interrupted. The query examined at least 16 rows, which exceeds LIMIT ROWS EXAMINED (15). The query result may be incomplete EXPLAIN SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14; id select_type table type possible_keys key key_len ref rows Extra @@ -833,13 +835,15 @@ CREATE TABLE t2 ( b INT, c INT, KEY(c) ); INSERT INTO t2 VALUES (5, 0),(3, 4),(6, 1), (5, 8),(4, 9),(8, 1); +set expensive_subquery_limit=5; SELECT (SELECT MAX(c) FROM t1, t2) FROM t2 WHERE c = (SELECT MAX(b) FROM t2) LIMIT ROWS EXAMINED 3; (SELECT MAX(c) FROM t1, t2) Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete +Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete +set expensive_subquery_limit=default; drop table t1, t2; MDEV-178: LIMIT ROWS EXAMINED: Assertion `0' failed in net_end_statement(THD*) on the diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test index 2315580..c5ad7e4 100644 --- a/mysql-test/main/limit_rows_examined.test +++ b/mysql-test/main/limit_rows_examined.test @@ -445,11 +445,11 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0); EXPLAIN SELECT DISTINCT a AS field1 FROM t1, t2 WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d) -HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20; +HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15; SELECT DISTINCT a AS field1 FROM t1, t2 WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d) -HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20; +HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15; EXPLAIN SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14; @@ -550,11 +550,15 @@ INSERT INTO t2 VALUES (5, 0),(3, 4),(6, 1), (5, 8),(4, 9),(8, 1); +set expensive_subquery_limit=5; + SELECT (SELECT MAX(c) FROM t1, t2) FROM t2 WHERE c = (SELECT MAX(b) FROM t2) LIMIT ROWS EXAMINED 3; +set expensive_subquery_limit=default; + drop table t1, t2; --echo diff --git a/mysql-test/main/outfile.result b/mysql-test/main/outfile.result index 4c439c3..50ae130 100644 Binary files a/mysql-test/main/outfile.result and b/mysql-test/main/outfile.result differ diff --git a/mysql-test/main/outfile.test b/mysql-test/main/outfile.test index 9f2fc22..e5294f0 100644 --- a/mysql-test/main/outfile.test +++ b/mysql-test/main/outfile.test @@ -62,6 +62,7 @@ select load_file(concat(@tmpdir,"/outfile-test.4")); # CREATE TABLE t1 (a INT); +--error ER_OPTION_PREVENTS_STATEMENT EXPLAIN SELECT * INTO OUTFILE '/tmp/t1.txt' diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result index 25465fe..829e6fa 100644 --- a/mysql-test/main/subselect_mat.result +++ b/mysql-test/main/subselect_mat.result @@ -2875,7 +2875,7 @@ EXPLAIN SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used -3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1) diff --git a/mysql-test/main/type_year.result b/mysql-test/main/type_year.result index aaee504..b99a566 100644 --- a/mysql-test/main/type_year.result +++ b/mysql-test/main/type_year.result @@ -398,7 +398,6 @@ a 00 select a from t1 where a=y2k(); a -00 select a from t1 where a=b; a drop table t1; diff --git a/mysql-test/main/warnings_1.result b/mysql-test/main/warnings_1.result new file mode 100644 index 0000000..bc14f92 --- /dev/null +++ b/mysql-test/main/warnings_1.result @@ -0,0 +1,11 @@ +drop temporary table if exists not_exists; +Warnings: +Note 1051 Unknown table 'test.not_exists' +drop table if exists not_exists_table; +Warnings: +Note 1051 Unknown table 'test.not_exists_table' +prepare stmt from "show count(*) warnings;"; +execute stmt; +@@session.warning_count +1 +deallocate prepare stmt; diff --git a/mysql-test/main/warnings_1.test b/mysql-test/main/warnings_1.test new file mode 100644 index 0000000..8773ac2 --- /dev/null +++ b/mysql-test/main/warnings_1.test @@ -0,0 +1,5 @@ +drop temporary table if exists not_exists; +drop table if exists not_exists_table; +prepare stmt from "show count(*) warnings;"; +execute stmt; +deallocate prepare stmt; diff --git a/sql/field.cc b/sql/field.cc index 862c40b..68fa0ff 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1387,7 +1387,9 @@ bool Field::can_optimize_range(const Item_bool_func *cond, { DBUG_ASSERT(cmp_type() != TIME_RESULT); // Handled in Field_temporal DBUG_ASSERT(cmp_type() != STRING_RESULT); // Handled in Field_str descendants - return item->cmp_type() != TIME_RESULT; + return (item->cmp_type() != TIME_RESULT) && + !(item->type() == Item::SUBSELECT_ITEM && + ((Item_subselect *)item)->is_expensive()); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index a65cbbf..941452f 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5704,6 +5704,8 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str, bool escape_used_in_parsing, CHARSET_INFO *cmp_cs, int *escape) { + if (thd->lex->context_analysis_only) + return false; /* ESCAPE clause accepts only constant arguments and Item_param. @@ -5713,9 +5715,13 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str, reach val_int(), so we won't need the value. CONTEXT_ANALYSIS_ONLY_DERIVED being a notable exception here. */ +#if 0 if (!escape_item->const_during_execution() || (!escape_item->const_item() && !(thd->lex->context_analysis_only & ~CONTEXT_ANALYSIS_ONLY_DERIVED))) +#else + if (!escape_item->const_item()) +#endif { my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE"); return TRUE; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index c79735e..34d7e64 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1018,7 +1018,11 @@ table_map Item_subselect::used_tables() const bool Item_subselect::const_item() const { DBUG_ASSERT(thd); - return (thd->lex->context_analysis_only || with_recursive_reference ? + if (unit->executed_at_prepare_phase() && !thd->lex->context_analysis_only) + return true; + return (!(thd->lex->m_sql_cmd && + thd->lex->m_sql_cmd->is_prepared()) || + with_recursive_reference ? FALSE : forced_const || const_item_cache); } diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 81ea002..37fc679 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -4216,6 +4216,8 @@ my_bool Query_cache::ask_handler_allowance(THD *thd, for (; tables_used; tables_used= tables_used->next_global) { + if (tables_used->is_view_or_derived()) + continue; TABLE *table; handler *handler; if (!(table= tables_used->table)) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7c1064c..634d5f2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -643,6 +643,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) table_map_for_update(0), m_examined_row_count(0), accessed_rows_and_keys(0), + accessed_rows_and_keys_at_exec_start(0), m_digest(NULL), m_statement_psi(NULL), m_transaction_psi(NULL), diff --git a/sql/sql_class.h b/sql/sql_class.h index 1bc9e7e..9bb4d6b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3398,6 +3398,7 @@ class THD: public THD_count, /* this must be first */ changed or written. */ ulonglong accessed_rows_and_keys; + ulonglong accessed_rows_and_keys_at_exec_start; /** Check if the number of rows accessed by a statement exceeded @@ -3405,7 +3406,8 @@ class THD: public THD_count, /* this must be first */ */ void check_limit_rows_examined() { - if (++accessed_rows_and_keys > lex->limit_rows_examined_cnt) + if ((++accessed_rows_and_keys - accessed_rows_and_keys_at_exec_start) > + lex->limit_rows_examined_cnt) set_killed(ABORT_QUERY); } diff --git a/sql/sql_delete.h b/sql/sql_delete.h index ad018ed..50d37ce 100644 --- a/sql/sql_delete.h +++ b/sql/sql_delete.h @@ -84,7 +84,7 @@ class Sql_cmd_delete final : public Sql_cmd_dml private: /** - @biefSpecial handling of single-table deletes after prepare phase + @brief Special handling of single-table deletes after prepare phase */ bool delete_from_single_table(THD *thd); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ba03fe9..0611e35 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -5544,3 +5544,130 @@ void select_create::abort_result_set() (void) create_info->finalize_locked_tables(thd, true); DBUG_VOID_RETURN; } + + +bool Sql_cmd_insert_base::precheck(THD *thd) +{ +#if 0 + /* + Since INSERT DELAYED doesn't support temporary tables, we could + not pre-open temporary tables for SQLCOM_INSERT / SQLCOM_REPLACE. + Open them here instead. + */ + if (first_table->lock_type != TL_WRITE_DELAYED && + thd->open_temporary_tables(lex->query_tables)) + return true; + + if (insert_precheck(thd, lex->query_tables)) + return true; + + WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE); + + return false; + +#ifdef WITH_WSREP +wsrep_error_label: +#endif +#endif + return true; +} + + +bool Sql_cmd_insert_base::prepare_inner(THD *thd) +{ +#if 0 + SELECT_LEX *const select_lex= thd->lex->first_select_lex(); + TABLE_LIST *const table_list= select_lex->get_table_list(); + Name_resolution_context *context= &select_lex->context; + Name_resolution_context_state ctx_state; + const bool select_insert= insert_many_values.elements == 0; + bool insert_into_view= (table_list->view != 0); + TABLE *table; + + DBUG_ENTER("Sql_cmd_insert_base::prepare_inner"); + + (void) read_statistics_for_tables_if_needed(thd, table_list); + + { + if (mysql_handle_derived(lex, DT_INIT)) + DBUG_RETURN(TRUE); + if (mysql_handle_derived(lex, DT_MERGE_FOR_INSERT)) + DBUG_RETURN(TRUE); + if (mysql_handle_derived(lex, DT_PREPARE)) + DBUG_RETURN(TRUE); + } + + insert_field_list= thd->lex->field_list; + + if (duplicates == DUP_UPDATE) + { + /* it should be allocated before Item::fix_fields() */ + if (table_list->set_insert_values(thd->mem_root)) + DBUG_RETURN(TRUE); + } + + table= table_list->table; + + if (table->file->check_if_updates_are_ignored("INSERT")) + DBUG_RETURN(-1); + + if (!table_list->single_table_updatable()) + { + my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT"); + DBUG_RETURN(TRUE); + } + + /* + first table in list is the one we'll INSERT into, requires INSERT_ACL. + all others require SELECT_ACL only. the ACL requirement below is for + new leaves only anyway (view-constituents), so check for SELECT rather + than INSERT. + */ + if (setup_tables_and_check_access(thd, + &select_lex->context, + &select_lex->top_join_list, + table_list, + select_lex->leaf_tables, + select_insert, INSERT_ACL, SELECT_ACL, + TRUE)) + DBUG_RETURN(TRUE); + + if (insert_into_view && !insert_field_list.elements) + { + thd->lex->empty_field_list_on_rset= 1; + if (!table_list->table || table_list->is_multitable()) + { + my_error(ER_VIEW_NO_INSERT_FIELD_LIST, MYF(0), + table_list->view_db.str, table_list->view_name.str); + DBUG_RETURN(TRUE); + } + if (insert_view_fields(thd, &insert_field_list, table_list)) + DBUG_RETURN(TRUE); + } + + if (thd->lex->has_returning()) + { + status_var_increment(thd->status_var.feature_insert_returning); + + /* This is INSERT ... RETURNING. It will return output to the client */ + if (thd->lex->analyze_stmt) + { + /* + Actually, it is ANALYZE .. INSERT .. RETURNING. We need to produce + output and then discard it. + */ + result= new (thd->mem_root) select_send_analyze(thd); + save_protocol= thd->protocol; + thd->protocol= new Protocol_discard(thd); + } + else + { + if (!(result= new (thd->mem_root) select_send(thd))) + DBUG_RETURN(TRUE); + } + } +#else + return false; +#endif +} + diff --git a/sql/sql_insert.h b/sql/sql_insert.h index 8b034c2..eae3b53 100644 --- a/sql/sql_insert.h +++ b/sql/sql_insert.h @@ -18,6 +18,7 @@ #include "sql_class.h" /* enum_duplicates */ #include "sql_list.h" +#include "sql_base.h" /* Instead of including sql_lex.h we add this typedef here */ typedef List<Item> List_item; @@ -51,4 +52,139 @@ bool binlog_drop_table(THD *thd, TABLE *table); inline void kill_delayed_threads(void) {} #endif + +/** + Base class for all INSERT and REPLACE statements. Abstract class that + is inherited by Sql_cmd_insert_values and Sql_cmd_insert_select. +*/ + +class Sql_cmd_insert_base : public Sql_cmd_dml +{ +protected: + virtual bool precheck(THD *thd) override; + + virtual bool prepare_inner(THD *thd) override; + +private: + bool resolve_update_expressions(THD *thd); + bool prepare_values_table(THD *thd); + bool resolve_values_table_columns(THD *thd); + + /** + Field list to insert/replace + + One of two things: + 1. For the INSERT/REPLACE ... (col1, ... colN) VALUES ... syntax + this is a list of col1, ..., colN fields. + 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension + this is a list of col1, ... colM fields as well. + */ + List<Item> insert_field_list; + +public: + /* + field_list was created for view and should be removed before PS/SP + rexecuton + */ + bool empty_field_list_on_rset; + + DML_prelocking_strategy *get_dml_prelocking_strategy() + { + return &dml_prelocking_strategy; + } + +protected: + const bool is_replace; + + /** + Row data to insert/replace + + One of two things: + 1. For the INSERT/REPLACE ... VALUES (row1), (row2), ... (rowN) syntax + the list contains N List_item lists: one List_item per row. + 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension + this list contains only 1 List_item of M data values: this way we + emulate this syntax: + INSERT/REPLACE ... (col1, ... colM) VALUE (x1, ..., xM); + */ + List<List_item> insert_many_values; + + /* + Number of values per row in insert_many_values, available after resolving + */ + uint value_count; + + /* ON DUPLICATE KEY UPDATE field list */ + List<Item> update_field_list; + + const enum_duplicates duplicates; + + Protocol *save_protocol; /**< needed for ANALYZE .. INSERT .. RETURNING */ + + explicit Sql_cmd_insert_base(bool is_replace_arg, + enum_duplicates duplicates_arg) + : empty_field_list_on_rset(false), + is_replace(is_replace_arg), + value_count(0), + duplicates(duplicates_arg), + save_protocol(NULL) + {} + +#if 0 + virtual void cleanup(THD *thd) override + { + if (empty_field_list_on_rset) + { + empty_field_list_on_rset = false; + insert_field_list.empty(); + } + } +#endif + +private: + + /* The prelocking strategy used when opening the used tables */ + DML_prelocking_strategy dml_prelocking_strategy; + +}; + + +/** + Class that implements INSERT ... VALUES and REPLACE ... VALUES statements. +*/ + +class Sql_cmd_insert_values final : public Sql_cmd_insert_base +{ +public: + explicit Sql_cmd_insert_values(bool is_replace_arg, + enum_duplicates duplicates_arg) + : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {} + + enum_sql_command sql_command_code() const + { + return is_replace ? SQLCOM_REPLACE : SQLCOM_INSERT; + } + +}; + + +/** + Class that implements INSERT ... SELECT and REPLACE ... SELECT statements. +*/ + +class Sql_cmd_insert_select final : public Sql_cmd_insert_base +{ +public: + explicit Sql_cmd_insert_select(bool is_replace_arg, + enum_duplicates duplicates_arg) + : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {} + + enum_sql_command sql_command_code() const + { + return is_replace ? SQLCOM_REPLACE_SELECT : SQLCOM_INSERT_SELECT; + } +}; + + + #endif /* SQL_INSERT_INCLUDED */ diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 7191465..bd6c9ed 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -42,6 +42,8 @@ #endif #include "sql_update.h" // class Sql_cmd_update #include "sql_delete.h" // class Sql_cmd_delete +#include "sql_insert.h" // class Sql_cmd_insert + void LEX::parse_error(uint err_number) { @@ -10352,13 +10354,19 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit) bool LEX::parsed_insert_select(SELECT_LEX *first_select) { + bool is_insert_or_replace= false; + bool is_replace= false; if (sql_command == SQLCOM_INSERT || sql_command == SQLCOM_REPLACE) { + is_insert_or_replace= true; if (sql_command == SQLCOM_INSERT) sql_command= SQLCOM_INSERT_SELECT; else + { + is_replace= true; sql_command= SQLCOM_REPLACE_SELECT; + } } insert_select_hack(first_select); if (check_main_unit_semantics()) @@ -10368,6 +10376,23 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select) SELECT_LEX *blt __attribute__((unused))= pop_select(); DBUG_ASSERT(blt == &builtin_select); push_select(first_select); + + if (is_insert_or_replace) + { + if (sql_command == SQLCOM_INSERT || sql_command == SQLCOM_REPLACE) + { + if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_values(is_replace, + duplicates))) + return true; + } + else + { + if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_select(is_replace, + duplicates))) + return true; + } + } + return false; } @@ -10450,6 +10475,8 @@ bool LEX::select_finalize(st_select_lex_unit *expr) { sql_command= SQLCOM_SELECT; selects_allow_procedure= TRUE; + if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_select(result))) + return true; if (set_main_unit(expr)) return true; return check_main_unit_semantics(); @@ -11921,3 +11948,27 @@ bool SELECT_LEX_UNIT::is_derived_eliminated() const return false; return derived->table->map & outer_select()->join->eliminated_tables; } + +bool SELECT_LEX_UNIT::executed_at_prepare_phase() +{ + for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) + { + if (!sl->executed_at_prepare_phase()) + return false; + } + return true; +} + +bool SELECT_LEX::executed_at_prepare_phase() +{ + if (table_list.elements || is_correlated) + return false; + for (st_select_lex_unit *unit= first_inner_unit(); + unit; + unit= unit->next_unit()) + { + if (!unit->executed_at_prepare_phase()) + return false; + } + return true; +} diff --git a/sql/sql_lex.h b/sql/sql_lex.h index d1bdbb0..b11d4fe 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1034,6 +1034,8 @@ class st_select_lex_unit: public st_select_lex_node { bool explainable() const; + bool executed_at_prepare_phase(); + void reset_distinct(); void fix_distinct(); @@ -1475,6 +1477,8 @@ class st_select_lex: public st_select_lex_node ORDER *order, enum_query_type query_type); void print_limit(THD *thd, String *str, enum_query_type query_type); + bool prepare(THD *thd, select_result *result); + bool exec(THD *thd); void fix_prepare_information(THD *thd, Item **conds, Item **having_conds); /* Destroy the used execution plan (JOIN) of this subtree (this @@ -1648,6 +1652,7 @@ class st_select_lex: public st_select_lex_node bool is_unit_nest() { return (nest_flags & UNIT_NEST_FL); } void mark_as_unit_nest() { nest_flags= UNIT_NEST_FL; } bool is_sj_conversion_prohibited(THD *thd); + bool executed_at_prepare_phase(); }; typedef class st_select_lex SELECT_LEX; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7f95665..c769baa 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3903,7 +3903,9 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) case SQLCOM_SHOW_COLLATIONS: case SQLCOM_SHOW_STORAGE_ENGINES: case SQLCOM_SHOW_PROFILE: +#if 0 case SQLCOM_SELECT: +#endif { #ifdef WITH_WSREP if (lex->sql_command == SQLCOM_SELECT) @@ -4376,6 +4378,17 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) res = mysql_checksum_table(thd, first_table, &lex->check_opt); break; } + case SQLCOM_SELECT: + { + res = lex->m_sql_cmd->execute(thd); + break; + } +#if 0 + case SQLCOM_REPLACE: + case SQLCOM_INSERT: + case SQLCOM_REPLACE_SELECT: + case SQLCOM_INSERT_SELECT: +#endif case SQLCOM_UPDATE: case SQLCOM_UPDATE_MULTI: case SQLCOM_DELETE: @@ -4388,6 +4401,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) thd->abort_on_warning= 0; break; } +#if 1 case SQLCOM_REPLACE: if ((res= generate_incident_event(thd))) break; @@ -4647,6 +4661,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) break; } +#endif case SQLCOM_DROP_SEQUENCE: case SQLCOM_DROP_TABLE: { @@ -7346,6 +7361,7 @@ void THD::reset_for_next_command(bool do_clear_error) get_stmt_da()->reset_for_next_command(); m_sent_row_count= m_examined_row_count= 0; accessed_rows_and_keys= 0; + accessed_rows_and_keys_at_exec_start= 0; reset_slow_query_state(); @@ -7485,6 +7501,8 @@ void create_select_for_variable(THD *thd, LEX_CSTRING *var_name) lex= thd->lex; lex->init_select(); lex->sql_command= SQLCOM_SELECT; + lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_select(thd->lex->result); + /* We set the name of Item to @@session.var_name because that then is used as the column name in the output. diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 7828f8a..bc9071a 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2268,6 +2268,48 @@ static bool check_prepared_statement(Prepared_statement *stmt) lex->m_sql_cmd->unprepare(thd); break; + case SQLCOM_SELECT: +#if 0 + if (lex->m_sql_cmd == NULL && + !(lex->m_sql_cmd= + new (thd->mem_root) Sql_cmd_select(thd->lex->result))) + { + res= 1; + break; + } +#endif + lex->m_sql_cmd->set_owner(stmt); + res = lex->m_sql_cmd->prepare(thd); + if (res == 2) + { + /* Statement and field info has already been sent */ + DBUG_RETURN(FALSE); + } + if (!res && !lex->describe && !lex->analyze_stmt && !stmt->is_sql_prepare()) + { + SELECT_LEX_UNIT *const unit = &lex->unit; + /* Make copy of item list, as change_columns may change it */ + SELECT_LEX_UNIT* master_unit= unit->first_select()->master_unit(); + bool is_union_op= + master_unit->is_unit_op() || master_unit->fake_select_lex; + + List<Item> fields(is_union_op ? unit->item_list : + lex->first_select_lex()->item_list); + + /* Change columns if a procedure like analyse() */ + res= (unit->last_procedure && + unit->last_procedure->change_columns(thd, fields)); + + if (res || send_prep_stmt(stmt, lex->result->field_count(fields)) || + lex->result->send_result_set_metadata(fields, + Protocol::SEND_EOF) || + thd->protocol->flush()) + res= true; + } + if (!res) + lex->m_sql_cmd->unprepare(thd); + break; + /* The following allow WHERE clause, so they must be tested like SELECT */ case SQLCOM_SHOW_DATABASES: case SQLCOM_SHOW_TABLES: @@ -2285,7 +2327,9 @@ static bool check_prepared_statement(Prepared_statement *stmt) case SQLCOM_SHOW_STATUS_FUNC: case SQLCOM_SHOW_STATUS_PACKAGE: case SQLCOM_SHOW_STATUS_PACKAGE_BODY: +#if 0 case SQLCOM_SELECT: +#endif res= mysql_test_select(stmt, tables); if (res == 2) { @@ -2469,12 +2513,14 @@ static bool check_prepared_statement(Prepared_statement *stmt) lex->describe, lex->analyze_stmt) || send_prep_stmt(stmt, result.field_count(field_list)) || result.send_result_set_metadata(field_list, - Protocol::SEND_EOF); + Protocol::SEND_EOF) || + thd->protocol->flush(); + } + else if (lex->sql_command != SQLCOM_SELECT) + { + res= send_prep_stmt(stmt, 0) || + thd->protocol->flush(); } - else - res= send_prep_stmt(stmt, 0); - if (!res) - thd->protocol->flush(); } DBUG_RETURN(FALSE); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a765a84..f51e987 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -54,6 +54,9 @@ #include "sql_cte.h" #include "sql_window.h" #include "tztime.h" +#ifdef WITH_WSREP +#include "wsrep_mysqld.h" +#endif #include "debug.h" #include "debug_sync.h" // DEBUG_SYNC @@ -4907,21 +4910,22 @@ void JOIN::cleanup_item_list(List<Item> &items) const 0 otherwise */ -select_handler *find_select_handler(THD *thd, - SELECT_LEX* select_lex) +select_handler *SELECT_LEX::find_select_handler(THD *thd) { - if (select_lex->next_select()) + if (next_select()) return 0; - if (select_lex->master_unit()->outer_select()) + if (master_unit()->outer_select()) return 0; TABLE_LIST *tbl= nullptr; - // For SQLCOM_INSERT_SELECT the server takes TABLE_LIST - // from thd->lex->query_tables and skips its first table - // b/c it is the target table for the INSERT..SELECT. + /* + For SQLCOM_INSERT_SELECT the server takes TABLE_LIST + from thd->lex->query_tables and skips its first table + b/c it is the target table for the INSERT..SELECT. + */ if (thd->lex->sql_command != SQLCOM_INSERT_SELECT) { - tbl= select_lex->join->tables_list; + tbl= join->tables_list; } else if (thd->lex->query_tables && thd->lex->query_tables->next_global) @@ -4938,7 +4942,7 @@ select_handler *find_select_handler(THD *thd, handlerton *ht= tbl->table->file->partition_ht(); if (!ht->create_select) continue; - select_handler *sh= ht->create_select(thd, select_lex); + select_handler *sh= ht->create_select(thd, this); return sh; } return 0; @@ -5054,7 +5058,7 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds, thd->get_stmt_da()->reset_current_row_for_warning(1); /* Look for a table owned by an engine with the select_handler interface */ - select_lex->pushdown_select= find_select_handler(thd, select_lex); + select_lex->pushdown_select= select_lex->find_select_handler(thd); if ((err= join->optimize())) { @@ -11730,7 +11734,8 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, (select thats very heavy) => is a constant here eg: (select avg(order_cost) from orders) => constant but expensive */ - if (!keyuse->val->used_tables() && !thd->lex->describe) + if (keyuse->val->const_item() && !keyuse->val->is_expensive() && + !thd->lex->describe) { // Compare against constant store_key_item tmp(thd, keyinfo->key_part[i].field, @@ -30958,6 +30963,9 @@ static void MYSQL_DML_START(THD *thd) { switch (thd->lex->sql_command) { + case SQLCOM_SELECT: + MYSQL_INSERT_START(thd->query()); + break; case SQLCOM_UPDATE: MYSQL_UPDATE_START(thd->query()); break; @@ -30980,6 +30988,9 @@ static void MYSQL_DML_DONE(THD *thd, int rc) { switch (thd->lex->sql_command) { + case SQLCOM_SELECT: + MYSQL_SELECT_DONE(rc, (rc ? 0 : (ulong) (thd->limit_found_rows))); + break; case SQLCOM_UPDATE: MYSQL_UPDATE_DONE( rc, @@ -31046,8 +31057,6 @@ bool Sql_cmd_dml::prepare(THD *thd) MYSQL_DML_START(thd); - lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_DERIVED; - if (open_tables_for_query(thd, lex->query_tables, &table_count, 0, get_dml_prelocking_strategy())) { @@ -31060,8 +31069,6 @@ bool Sql_cmd_dml::prepare(THD *thd) if (prepare_inner(thd)) goto err; - lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_DERIVED; - set_prepared(); unit->set_prepared(); @@ -31137,6 +31144,7 @@ bool Sql_cmd_dml::execute(THD *thd) { if (lock_tables(thd, lex->query_tables, table_count, 0)) goto err; + query_cache_store_query(thd, thd->lex->query_tables); } unit->set_limit(select_lex); @@ -31189,8 +31197,266 @@ bool Sql_cmd_dml::execute(THD *thd) bool Sql_cmd_dml::execute_inner(THD *thd) { SELECT_LEX_UNIT *unit = &lex->unit; - SELECT_LEX *select_lex= unit->first_select(); - JOIN *join= select_lex->join; + DBUG_ENTER("Sql_cmd_dml::execute_inner"); + + if (unit->is_unit_op() || unit->fake_select_lex) + { + if (unit->exec()) + DBUG_RETURN(true); + } +#if 1 + else + { + SELECT_LEX *select_lex= unit->first_select(); + if (select_lex->exec(thd)) + DBUG_RETURN(true); + } +#endif + + DBUG_RETURN(false); +} + + +bool Sql_cmd_select::precheck(THD *thd) +{ + bool rc= false; + + privilege_t privileges_requested= SELECT_ACL; + + if (lex->exchange) + { + /* + lex->exchange != NULL implies SELECT .. INTO OUTFILE and this + requires FILE_ACL access. + */ + privileges_requested|= FILE_ACL; + } + + TABLE_LIST *tables = thd->lex->query_tables; + + if (tables) + rc= check_table_access(thd, privileges_requested, + tables, false, UINT_MAX, false); + else + rc= check_access(thd, privileges_requested, + any_db.str, NULL, NULL, false, false); + +#ifdef WITH_WSREP + if (lex->sql_command == SQLCOM_SELECT) + { + WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_READ); + } + else + { + WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW); +# ifdef ENABLED_PROFILING + if (lex->sql_command == SQLCOM_SHOW_PROFILE) + thd->profiling.discard_current_query(); +# endif + } +#endif /* WITH_WSREP */ + + if (!rc) + return false; + +#ifdef WITH_WSREP +wsrep_error_label: +#endif + return true; +} + + + +bool Sql_cmd_select::prepare_inner(THD *thd) +{ + bool rc= false; + LEX *lex= thd->lex; + TABLE_LIST *tables= lex->query_tables; + SELECT_LEX_UNIT *const unit = &lex->unit; + + DBUG_ENTER("Sql_cmd_select::prepare_inner"); + + if (!thd->stmt_arena->is_stmt_prepare()) + (void) read_statistics_for_tables_if_needed(thd, tables); + + { + if (mysql_handle_derived(lex, DT_INIT)) + DBUG_RETURN(TRUE); + } + + if (thd->stmt_arena->is_stmt_prepare()) + { + if (!result) + { + Query_arena backup; + Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup); + result= new (thd->mem_root) select_send(thd); + if (arena) + thd->restore_active_arena(arena, &backup); + thd->lex->result= result; + } + rc= unit->prepare(unit->derived, 0, 0); + + } + else + { + if (lex->analyze_stmt) + { + if (result && result->result_interceptor()) + result->result_interceptor()->disable_my_ok_calls(); + else + { + DBUG_ASSERT(thd->protocol); + result= new (thd->mem_root) select_send_analyze(thd); + save_protocol= thd->protocol; + thd->protocol= new Protocol_discard(thd); + } + } + else if (!(result= lex->result)) + result= new (thd->mem_root) select_send(thd); + if (!result) + DBUG_RETURN(TRUE); + + SELECT_LEX *parameters = unit->global_parameters(); + if (!parameters->limit_params.explicit_limit) + { + parameters->limit_params.select_limit = + new (thd->mem_root) Item_int(thd, + (ulonglong) thd->variables.select_limit); + if (parameters->limit_params.select_limit == NULL) + DBUG_RETURN(true); /* purecov: inspected */ + } + ulonglong select_options= 0; + if (lex->describe) + select_options|= SELECT_DESCRIBE; + if (unit->is_unit_op() || unit->fake_select_lex) + select_options|= SELECT_NO_UNLOCK; + rc= unit->prepare(unit->derived, result, select_options); + + if (rc && thd->lex->analyze_stmt && save_protocol) + { + delete thd->protocol; + thd->protocol= save_protocol; + } + } + + DBUG_RETURN(rc); +} + + +bool Sql_cmd_select::execute_inner(THD *thd) +{ + DBUG_ENTER("Sql_cmd_select::execute_inner"); + + thd->status_var.last_query_cost= 0.0; + + bool res= Sql_cmd_dml::execute_inner(thd); + + res|= thd->is_error(); + if (unlikely(res)) + result->abort_result_set(); + + if (result != thd->lex->result) + { + delete result; + result= 0; + } + + if (lex->analyze_stmt) + { + if (save_protocol) + { + delete thd->protocol; + thd->protocol= save_protocol; + } + if (!res) + res= thd->lex->explain->send_explain(thd); + } + + if (thd->lex->describe) + { + if (!res) + res= thd->lex->explain->send_explain(thd); + + if (!res && (thd->lex->describe & DESCRIBE_EXTENDED)) + { + char buff[1024]; + String str(buff,(uint32) sizeof(buff), system_charset_info); + str.length(0); + /* + The warnings system requires input in utf8, @see + mysqld_show_warnings(). + */ + lex->unit.print(&str, QT_EXPLAIN_EXTENDED); + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_YES, str.c_ptr_safe()); + } + } + + if (unlikely(thd->killed == ABORT_QUERY && !thd->no_errors)) + { + /* + If LIMIT ROWS EXAMINED interrupted query execution, issue a warning, + continue with normal processing and produce an incomplete query result. + */ + bool saved_abort_on_warning= thd->abort_on_warning; + thd->abort_on_warning= false; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT, + ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT), + thd->accessed_rows_and_keys - + thd->accessed_rows_and_keys_at_exec_start, + thd->lex->limit_rows_examined->val_uint()); + thd->abort_on_warning= saved_abort_on_warning; + thd->reset_killed(); + } + /* Disable LIMIT ROWS EXAMINED after query execution. */ + thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX; + + /* Count number of empty select queries */ + if (!thd->get_sent_row_count() && !res) + status_var_increment(thd->status_var.empty_queries); + else + status_var_add(thd->status_var.rows_sent, thd->get_sent_row_count()); + + DBUG_RETURN(res); +} + + +bool st_select_lex::prepare(THD *thd, select_result *result) +{ + ulonglong select_options= options | thd->variables.option_bits; + + DBUG_ENTER("st_select_lex::prepare"); + + if (thd->lex->describe) + select_options|= SELECT_DESCRIBE; + + if (!(join= new (thd->mem_root) JOIN(thd, item_list, + select_options, result))) + DBUG_RETURN(true); + + SELECT_LEX_UNIT *unit= master_unit(); + + thd->lex->used_tables=0; + + if (join->prepare(table_list.first, where, + order_list.elements + group_list.elements, + order_list.first, false, group_list.first, + having, thd->lex->proc_list.first, + this, unit)) + DBUG_RETURN(true); + + DBUG_RETURN(false); +} + + +bool st_select_lex::exec(THD *thd) +{ + DBUG_ENTER("st_select_lex::exec"); + + /* Look for a table owned by an engine with the select_handler interface */ + pushdown_select= find_select_handler(thd); if (join->optimize()) goto err; @@ -31204,18 +31470,28 @@ bool Sql_cmd_dml::execute_inner(THD *thd) if (unlikely(thd->is_error())) goto err; + thd->get_stmt_da()->reset_current_row_for_warning(1); + + if (master_unit()->outer_select() == NULL) + thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys; + join->exec(); if (thd->lex->describe & DESCRIBE_EXTENDED) { - select_lex->where= join->conds_history; - select_lex->having= join->having_history; + where= join->conds_history; + having= join->having_history; } err: - return join->error; -} + if (pushdown_select) + { + delete pushdown_select; + pushdown_select= NULL; + } + DBUG_RETURN(join->error); +} /** @} (end of group Query_Optimizer) diff --git a/sql/sql_select.h b/sql/sql_select.h index 48452ce..3574930 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -33,6 +33,8 @@ #include "records.h" /* READ_RECORD */ #include "opt_range.h" /* SQL_SELECT, QUICK_SELECT_I */ #include "filesort.h" +#include "sql_base.h" +#include "sql_cmd.h" typedef struct st_join_table JOIN_TAB; /* Values in optimize */ @@ -2516,4 +2518,39 @@ void propagate_new_equalities(THD *thd, Item *cond, bool *is_simplifiable_cond); bool dbug_user_var_equals_str(THD *thd, const char *name, const char *value); + + +class Sql_cmd_select : public Sql_cmd_dml +{ +public: + explicit Sql_cmd_select(select_result *result_arg) + : Sql_cmd_dml(), save_protocol(NULL) + { result= result_arg; } + + enum_sql_command sql_command_code() const override + { + return SQLCOM_SELECT; + } + + DML_prelocking_strategy *get_dml_prelocking_strategy() + { + return &dml_prelocking_strategy; + } + +protected: + + bool precheck(THD *thd) override; + + bool prepare_inner(THD *thd) override; + + bool execute_inner(THD *thd) override; + +private: + /* The prelocking strategy used when opening the used tables */ + DML_prelocking_strategy dml_prelocking_strategy; + + Protocol *save_protocol; +}; + + #endif /* SQL_SELECT_INCLUDED */ diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 0a92422..a61453d 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1324,6 +1324,24 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, describe= additional_options & SELECT_DESCRIBE; + if (describe) + { + for (SELECT_LEX *sl= first_sl; sl; sl= sl->next_select()) + { + sl->set_explain_type(FALSE); + sl->options|= SELECT_DESCRIBE; + } + if (is_unit_op() || fake_select_lex) + { + if (union_needs_tmp_table() && fake_select_lex) + { + fake_select_lex->select_number= FAKE_SELECT_LEX_ID; // just for initialization + fake_select_lex->type= unit_operation_text[common_op()]; + fake_select_lex->options|= SELECT_DESCRIBE; + } + } + } + /* Save fake_select_lex in case we don't need it for anything but global parameters. @@ -2159,6 +2177,8 @@ bool st_select_lex_unit::exec() DBUG_ENTER("st_select_lex_unit::exec"); bool was_executed= executed; + describe= thd->lex->describe; + if (executed && !uncacheable && !describe) DBUG_RETURN(FALSE); executed= 1; @@ -2167,6 +2187,9 @@ bool st_select_lex_unit::exec() item->make_const(); saved_error= optimize(); + + if (outer_select() == NULL) + thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys; create_explain_query_if_not_exists(thd->lex, thd->mem_root); @@ -2238,6 +2261,7 @@ bool st_select_lex_unit::exec() saved_error= sl->join->optimize(); } } + if (likely(!saved_error)) { records_at_start= table->file->stats.records; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 6ba88a9..776d477 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -71,6 +71,7 @@ #include "json_table.h" #include "sql_update.h" #include "sql_delete.h" +#include "sql_insert.h" /* this is to get the bison compilation windows warnings out */ #ifdef _MSC_VER
1 0
0 0
[Commits] a66dcc1: MDEV-27624 Wrong result for nested left join using not_exists optimization
by IgorBabaev 27 Oct '22

27 Oct '22
revision-id: a66dcc1801c4b8caa3b93753036295107bf78a16 (mariadb-10.3.35-240-ga66dcc1) parent(s): 3a62ff7e8980239a39e85393c6a797bb7acf97ed author: Igor Babaev committer: Igor Babaev timestamp: 2022-10-26 22:08:32 -0700 message: MDEV-27624 Wrong result for nested left join using not_exists optimization This bug affected queries with nested left joins having the same last inner table such that not_exists optimization could be applied to the most inner outer join when optimizer chose to use join buffers. The bug could lead to producing wrong a result set. If the WHERE condition a query contains a conjunctive IS NULL predicate over a non-nullable column of an inner table of a not nested outer join then not_exists optimization can be applied to tho the outer join. With this optimization when looking for matches for a certain record from the outer table of the join the records of the inner table can be ignored right after the first match satisfying the ON condition is found. In the case of nested outer joins having the same last inner table this optimization still can be applied but only if all ON conditions of the embedding outer joins are satisfied. Such check was missing in the code that tried to apply not_exists optimization when join buffers were used for outer join operations. This problem has been already fixed in the patch for bug MDEV-7992. Yet there it was resolved only for the cases when join buffers were not used for outer joins. Approved by Oleksandr Byelkin <sanja(a)mariadb.com> --- mysql-test/main/join_nested.result | 52 +++++++++++++++++++++++++++++++++ mysql-test/main/join_nested.test | 38 ++++++++++++++++++++++++ mysql-test/main/join_nested_jcl6.result | 52 +++++++++++++++++++++++++++++++++ sql/sql_join_cache.cc | 35 ++++++++++++++++++---- 4 files changed, 171 insertions(+), 6 deletions(-) diff --git a/mysql-test/main/join_nested.result b/mysql-test/main/join_nested.result index 5ab94a6..1efb2e6 100644 --- a/mysql-test/main/join_nested.result +++ b/mysql-test/main/join_nested.result @@ -1999,3 +1999,55 @@ Note 1003 select `test`.`t3`.`pk` AS `pk`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.` DROP TABLE t1,t2,t3; set join_cache_level= @save_join_cache_level; set optimizer_switch=@save_optimizer_switch; +# +# MDEV-27624: Nested left joins with not_exists optimization +# for most inner left join +# +set @save_join_cache_level= @@join_cache_level; +CREATE TABLE t1 (a INT NOT NULL, b INT, c INT); +INSERT INTO t1 VALUES (1,1,1), (1,2,1), (1,3,1); +CREATE TABLE t2(a INT NOT NULL); +INSERT INTO t2 VALUES (1), (2); +CREATE TABLE t3(a INT not null, b INT); +INSERT INTO t3 VALUES (1, 1), (2, 1), (3, 1); +set join_cache_level = 0; +EXPLAIN SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Not exists +SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +a b c a a b +1 3 1 NULL NULL NULL +set join_cache_level = 2; +EXPLAIN SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Not exists; Using join buffer (incremental, BNL join) +SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +a b c a a b +1 3 1 NULL NULL NULL +DROP TABLE t1, t2, t3; +set join_cache_level= @save_join_cache_level; +# end of 10.3 tests diff --git a/mysql-test/main/join_nested.test b/mysql-test/main/join_nested.test index eaf754f..6b2ae9a 100644 --- a/mysql-test/main/join_nested.test +++ b/mysql-test/main/join_nested.test @@ -1419,3 +1419,41 @@ DROP TABLE t1,t2,t3; set join_cache_level= @save_join_cache_level; set optimizer_switch=@save_optimizer_switch; + +--echo # +--echo # MDEV-27624: Nested left joins with not_exists optimization +--echo # for most inner left join +--echo # + +set @save_join_cache_level= @@join_cache_level; + +CREATE TABLE t1 (a INT NOT NULL, b INT, c INT); +INSERT INTO t1 VALUES (1,1,1), (1,2,1), (1,3,1); + +CREATE TABLE t2(a INT NOT NULL); +INSERT INTO t2 VALUES (1), (2); + +CREATE TABLE t3(a INT not null, b INT); +INSERT INTO t3 VALUES (1, 1), (2, 1), (3, 1); + +let $q= +SELECT * +FROM t1 + LEFT JOIN + ( t2 LEFT JOIN t3 ON t2.a = t3.b ) + ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; + +set join_cache_level = 0; +eval EXPLAIN $q; +eval $q; + +set join_cache_level = 2; +eval EXPLAIN $q; +eval $q; + +DROP TABLE t1, t2, t3; + +set join_cache_level= @save_join_cache_level; + +--echo # end of 10.3 tests diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result index 541cd47..338705c 100644 --- a/mysql-test/main/join_nested_jcl6.result +++ b/mysql-test/main/join_nested_jcl6.result @@ -2008,6 +2008,58 @@ Note 1003 select `test`.`t3`.`pk` AS `pk`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.` DROP TABLE t1,t2,t3; set join_cache_level= @save_join_cache_level; set optimizer_switch=@save_optimizer_switch; +# +# MDEV-27624: Nested left joins with not_exists optimization +# for most inner left join +# +set @save_join_cache_level= @@join_cache_level; +CREATE TABLE t1 (a INT NOT NULL, b INT, c INT); +INSERT INTO t1 VALUES (1,1,1), (1,2,1), (1,3,1); +CREATE TABLE t2(a INT NOT NULL); +INSERT INTO t2 VALUES (1), (2); +CREATE TABLE t3(a INT not null, b INT); +INSERT INTO t3 VALUES (1, 1), (2, 1), (3, 1); +set join_cache_level = 0; +EXPLAIN SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Not exists +SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +a b c a a b +1 3 1 NULL NULL NULL +set join_cache_level = 2; +EXPLAIN SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Not exists; Using join buffer (incremental, BNL join) +SELECT * +FROM t1 +LEFT JOIN +( t2 LEFT JOIN t3 ON t2.a = t3.b ) +ON t2.a = 1 AND (t3.b = t1.a AND t3.a > t1.b OR t3.a is NULL) +WHERE t1.c = 1 AND t3.a is NULL; +a b c a a b +1 3 1 NULL NULL NULL +DROP TABLE t1, t2, t3; +set join_cache_level= @save_join_cache_level; +# end of 10.3 tests CREATE TABLE t5 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); CREATE TABLE t6 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); CREATE TABLE t7 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 86df1d3..0804f4f 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2287,11 +2287,7 @@ enum_nested_loop_state JOIN_CACHE::join_matching_records(bool skip_last) int error; enum_nested_loop_state rc= NESTED_LOOP_OK; join_tab->table->null_row= 0; - bool check_only_first_match= - join_tab->check_only_first_match() && - (!join_tab->first_inner || // semi-join case - join_tab->first_inner == join_tab->first_unmatched); // outer join case - bool outer_join_first_inner= join_tab->is_first_inner_for_outer_join(); + bool check_only_first_match= join_tab->check_only_first_match(); DBUG_ENTER("JOIN_CACHE::join_matching_records"); /* Return at once if there are no records in the join buffer */ @@ -2355,7 +2351,34 @@ enum_nested_loop_state JOIN_CACHE::join_matching_records(bool skip_last) Also those records that must be null complemented are not considered as candidates for matches. */ - if ((!check_only_first_match && !outer_join_first_inner) || + + bool not_exists_opt_is_applicable= true; + if (check_only_first_match && join_tab->first_inner) + { + /* + This is the case with not_exists optimization for nested outer join + when join_tab is the last inner table for one or more embedding outer + joins. To safely use 'not_exists' optimization in this case we have + to check that the match flags for all these embedding outer joins are + in the 'on' state. + (See also a similar check in evaluate_join_record() for the case when + join buffer are not used.) + */ + for (JOIN_TAB *tab= join_tab->first_inner; + tab && tab->first_inner && tab->last_inner == join_tab; + tab= tab->first_inner->first_upper) + { + if (get_match_flag_by_pos_from_join_buffer(rec_ptr, tab) != + MATCH_FOUND) + { + not_exists_opt_is_applicable= false; + break; + } + } + } + + if (!check_only_first_match || + (join_tab->first_inner && !not_exists_opt_is_applicable) || !skip_next_candidate_for_match(rec_ptr)) { read_next_candidate_for_match(rec_ptr);
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • ...
  • 1461
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.