2 # UPDATE statements using index_merge optimization
5 # The include file works as intended only when index_merge_single_col_setup.inc
6 # or index_merge_multi_col_setup.inc is used. The table t1 set-up is done in
7 # these two include files.
10 DROP
TABLE IF EXISTS t2;
13 CREATE
TABLE t2 LIKE t1;
14 INSERT INTO t2 SELECT * FROM t1;
17 #1. UPDATE statements with various combinations of comparison operators
19 # intersect optimization technique test cases for non-selects
20 # are in a separate file(index_merge_intersect_dml.inc)
21 # due to different table requirements.
23 # union and sort_union
25 --let $query = WHERE key1=80 OR key4=49
27 --eval EXPLAIN UPDATE t1 SET key6=7 $query
28 --eval SELECT COUNT(*), SUM(key6) FROM t1 $query
29 --eval UPDATE t1 SET key6=7 $query
30 --eval SELECT COUNT(*), SUM(key6) FROM t1 $query
32 --let $query = WHERE (key3=80 AND key5 IS NULL) OR (key2=49 AND key6 IS NULL)
34 --eval EXPLAIN UPDATE t1 SET key1=18 $query
35 --eval SELECT COUNT(*), SUM(key1) FROM t1 $query
36 --eval UPDATE t1 SET key1=18 $query
37 --eval SELECT COUNT(*), SUM(key1) FROM t1 $query
39 --let $query = WHERE (key4=42 AND key6 IS NOT NULL) OR (key1>4 AND key5 IS NULL) AND key2<>50
41 --eval EXPLAIN UPDATE t1 SET key3=18 $query
42 --eval SELECT COUNT(*), SUM(key3) FROM t1 $query
43 --eval UPDATE t1 SET key3=18 $query
44 --eval SELECT COUNT(*), SUM(key3) FROM t1 $query
46 --let $query = WHERE key2=80 OR key3=1025 OR key4 <=> NULL
48 --eval EXPLAIN UPDATE t1 SET key8=64 $query
49 --eval SELECT COUNT(*), SUM(key8) FROM t1 $query
50 --eval UPDATE t1 SET key8=64 $query
51 --eval SELECT COUNT(*), SUM(key8) FROM t1 $query
53 --let $query = WHERE (key1 < 3 OR key2 < 2) AND (key3 < 3 OR key4 < 3) AND (key5 < 2 OR key6 < 2)
55 --eval EXPLAIN UPDATE t1 SET key8=18 $query
56 --eval SELECT COUNT(*), SUM(key8) FROM t1 $query
57 --eval UPDATE t1 SET key8=18 $query
58 --eval SELECT COUNT(*), SUM(key8) FROM t1 $query
60 --let $query = WHERE key1 between 25 AND 40 OR key2 between 15 AND 49
62 --eval EXPLAIN UPDATE t1 SET key3=32 $query
63 --eval SELECT COUNT(*), SUM(key3) FROM t1 $query
64 --eval UPDATE t1 SET key3=32 $query
65 --eval SELECT COUNT(*), SUM(key3) FROM t1 $query
67 --let $query = WHERE key1 IN (15,70) OR key2 IN (15,70)
69 --eval EXPLAIN UPDATE t1 SET key7=25 $query
70 --eval SELECT COUNT(*), SUM(key7) FROM t1 $query
71 --eval UPDATE t1 SET key7=25 $query
72 --eval SELECT COUNT(*), SUM(key7) FROM t1 $query
74 #2. Statement with ORDER BY
76 --let $query = WHERE key5<5 OR key8<10
ORDER BY key1
78 --eval EXPLAIN UPDATE t1 SET key1=10 $query
79 --eval SELECT COUNT(*), SUM(key1) FROM t1 $query
80 --eval UPDATE t1 SET key1=10 $query
81 --eval SELECT COUNT(*), SUM(key1) FROM t1 $query
83 #3. Multi table SQL statements
85 --let $query = t1 left join t2 ON (t2.key1=t2.key1) SET t1.key4=15 WHERE t1.key5=40 OR t1.key4=15
87 --eval EXPLAIN UPDATE $query
88 SELECT COUNT(*), SUM(key4) FROM t1;
90 SELECT COUNT(*), SUM(key4) FROM t1;
92 # Statements with subqueries
94 --let $query2 = key6 < ANY (SELECT key6 FROM t1 WHERE key1=10 OR key5=3)
95 --let $query1 = WHERE (key3=28 OR key4=10)
97 --eval EXPLAIN UPDATE t2 SET key7=7 $query1 AND $query2
98 --eval SELECT COUNT(*), SUM(key7) FROM t2 $query1 AND $query2
99 --eval UPDATE t2 SET key7=7 $query1 AND $query2
100 --eval SELECT COUNT(*), SUM(key7) FROM t2 $query1 AND $query2
102 --let $query3 = key1 < ANY (SELECT key1 FROM t1 WHERE key1<5 OR key4<7)
103 --let $query2 = key4 < SOME (SELECT key4 FROM t1 WHERE key1<5 OR key4<8)
104 --let $query1 = WHERE key1=25 OR key4=40
106 --eval EXPLAIN UPDATE t2 SET key2=2 $query1 AND ($query2 OR $query3)
107 --eval SELECT COUNT(*), SUM(key2) FROM t2 $query1 AND ($query2 OR $query3)
108 --eval UPDATE t2 SET key2=2 $query1 AND ($query2 OR $query3)
109 --eval SELECT COUNT(*), SUM(key2) FROM t2 $query1 AND ($query2 OR $query3)
111 --let $query = WHERE EXISTS (SELECT * FROM t1 WHERE key6<3 OR key4<10)
113 --eval EXPLAIN UPDATE t2 SET key3=20 $query
114 --eval SELECT COUNT(*), SUM(key3) FROM t2 $query
115 --eval UPDATE t2 SET key3=20 $query
116 --eval SELECT COUNT(*), SUM(key3) FROM t2 $query
118 # The following statement doesn't use index_merge optimization technique when
119 # the table is created with single column index setup.
121 --let $query = WHERE key5=80 OR key6=49
123 --eval EXPLAIN UPDATE t1 SET key8=50 $query
124 --eval SELECT COUNT(*), SUM(key8) FROM t1 $query
125 --eval UPDATE t1 SET key8=50 $query
126 --eval SELECT COUNT(*), SUM(key8) FROM t1 $query
129 # end of UPDATE statements