| 1 |
############################################################## |
| 2 |
# Purpose: Test multiple concurrect DML and DDL operations. |
| 3 |
# Currently with SPJ disabled, as that has its |
| 4 |
# own problems to be fixed in this area. |
| 5 |
# |
| 6 |
############################################################## |
| 7 |
--source include/have_multi_ndb.inc |
| 8 |
|
| 9 |
let $save_lock_wait_timeout = `select @@ndb_schema_dist_lock_wait_timeout`; |
| 10 |
set @@global.ndb_schema_dist_lock_wait_timeout = 240; |
| 11 |
|
| 12 |
connect (j1,localhost,root,,test); |
| 13 |
connect (j2,localhost,root,,test); |
| 14 |
connect (j3,localhost,root,,test); |
| 15 |
connect (ddl,localhost,root,,test); |
| 16 |
|
| 17 |
connection ddl; |
| 18 |
call mtr.add_suppression(".*NDB_SHARE.*Moving away for safety, but possible memleak"); |
| 19 |
|
| 20 |
create table parent(a int primary key, b int, key(b)) engine=ndb |
| 21 |
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"; |
| 22 |
create table child(a int, b int, primary key(a,b), key(b)) engine=ndb |
| 23 |
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"; |
| 24 |
|
| 25 |
insert into parent values (1,1), (2,2), (3,3), (4,4); |
| 26 |
insert into parent select a+4, b+4 from parent; |
| 27 |
insert into parent select a+8, b+8 from parent; |
| 28 |
insert into parent select a+16, b+16 from parent; |
| 29 |
insert into parent select a+32, b+32 from parent; |
| 30 |
insert into parent select a+64, b+64 from parent; |
| 31 |
insert into parent select a+128, b+128 from parent; |
| 32 |
insert into parent select a+256, b+256 from parent; |
| 33 |
insert into parent select a+512, b+512 from parent; |
| 34 |
insert into parent select a+1024, b+1024 from parent; |
| 35 |
insert into parent select a+2048, b+2048 from parent; |
| 36 |
insert into parent select a+4096, b+4096 from parent; |
| 37 |
|
| 38 |
insert into child select * from parent; |
| 39 |
analyze table parent, child; |
| 40 |
|
| 41 |
connection j1; |
| 42 |
set ndb_join_pushdown = off; |
| 43 |
|
| 44 |
# Use 'replace_column' to eliminate explained 'rows' which are unreliable |
| 45 |
--replace_column 10 ### 11 ### |
| 46 |
explain |
| 47 |
select straight_join count(*) |
| 48 |
from parent join child |
| 49 |
on child.a = parent.a and child.b = parent.b |
| 50 |
where parent.b > 5; |
| 51 |
|
| 52 |
--replace_column 10 ### 11 ### |
| 53 |
explain |
| 54 |
select straight_join count(*) |
| 55 |
from parent join child |
| 56 |
on child.a = parent.a |
| 57 |
where parent.b > 5; |
| 58 |
|
| 59 |
--replace_column 10 ### 11 ### |
| 60 |
explain |
| 61 |
select straight_join count(*) |
| 62 |
from parent join child |
| 63 |
on child.b = parent.b |
| 64 |
where parent.b > 5; |
| 65 |
|
| 66 |
show variables like 'server_id'; |
| 67 |
|
| 68 |
delimiter %; |
| 69 |
create procedure query_eq_ref_load (seconds int) |
| 70 |
begin |
| 71 |
set @x=time_to_sec(current_time()) + seconds; |
| 72 |
repeat |
| 73 |
set ndb_join_pushdown = off; |
| 74 |
select straight_join count(*) |
| 75 |
from parent join child |
| 76 |
on child.a = parent.a and child.b = parent.b |
| 77 |
where parent.b > 5; |
| 78 |
until @x <= time_to_sec(current_time()) |
| 79 |
end repeat; |
| 80 |
end% |
| 81 |
|
| 82 |
create procedure query_ref_load (seconds int) |
| 83 |
begin |
| 84 |
set @x=time_to_sec(current_time()) + seconds; |
| 85 |
repeat |
| 86 |
set ndb_join_pushdown = off; |
| 87 |
select straight_join count(*) |
| 88 |
from parent join child |
| 89 |
on child.a = parent.a and child.b = parent.b |
| 90 |
where parent.b > 5; |
| 91 |
until @x <= time_to_sec(current_time()) |
| 92 |
end repeat; |
| 93 |
end% |
| 94 |
|
| 95 |
create procedure query_ref_b_load (seconds int) |
| 96 |
begin |
| 97 |
set @x=time_to_sec(current_time()) + seconds; |
| 98 |
repeat |
| 99 |
set ndb_join_pushdown = off; |
| 100 |
select straight_join count(*) |
| 101 |
from parent join child |
| 102 |
on child.a = parent.a and child.b = parent.b |
| 103 |
where parent.b > 5; |
| 104 |
until @x <= time_to_sec(current_time()) |
| 105 |
end repeat; |
| 106 |
end% |
| 107 |
|
| 108 |
delimiter ;% |
| 109 |
|
| 110 |
|
| 111 |
--echo Starting background DML load |
| 112 |
|
| 113 |
connection j1; |
| 114 |
send call query_eq_ref_load(10); |
| 115 |
|
| 116 |
connection j2; |
| 117 |
send call query_ref_load(10); |
| 118 |
|
| 119 |
connection j3; |
| 120 |
send call query_ref_b_load(10); |
| 121 |
|
| 122 |
sleep 1; |
| 123 |
|
| 124 |
connection server2; |
| 125 |
show variables like 'server_id'; |
| 126 |
|
| 127 |
--echo Starting concurrent DDL operations |
| 128 |
alter table child add column c int; |
| 129 |
alter table child drop column c; |
| 130 |
|
| 131 |
#sleep 1; |
| 132 |
alter table child drop primary key; |
| 133 |
alter table child add primary key(b); |
| 134 |
|
| 135 |
#sleep 1; |
| 136 |
alter table child drop primary key; |
| 137 |
alter table child add primary key(a,b) using hash; |
| 138 |
|
| 139 |
#sleep 1; |
| 140 |
alter table child drop primary key; |
| 141 |
alter table child add primary key(a,b); |
| 142 |
|
| 143 |
#sleep 1; |
| 144 |
--echo Completed DDL operations, rejoins with DML load. |
| 145 |
--disable_result_log |
| 146 |
|
| 147 |
# We may fail with error 1412: Table definition has changed, |
| 148 |
# or error 1146: Table ... doesn't exist |
| 149 |
# or error 1296: Got error 3 Unknown error code' |
| 150 |
# ... The later is a bit strange, but likely due to poor error |
| 151 |
# handling in NDB. |
| 152 |
# |
| 153 |
connection j1; |
| 154 |
--error 0,1412,1146,1296 |
| 155 |
reap; |
| 156 |
|
| 157 |
connection j2; |
| 158 |
--error 0,1412,1146,1296 |
| 159 |
reap; |
| 160 |
|
| 161 |
connection j3; |
| 162 |
--error 0,1412,1146,1296 |
| 163 |
reap; |
| 164 |
|
| 165 |
--enable_result_log |
| 166 |
|
| 167 |
|
| 168 |
--echo ==================================================== |
| 169 |
--echo Force a 'trailing share' to be created in order to |
| 170 |
--echo check correct cleanup in ndbcluster_real_free_share() |
| 171 |
--echo ===================================================== |
| 172 |
let $query = |
| 173 |
select straight_join * |
| 174 |
from parent join child |
| 175 |
on child.a = parent.a and child.b = parent.b |
| 176 |
where parent.b > 5; |
| 177 |
|
| 178 |
connection server1; |
| 179 |
set ndb_join_pushdown = off; |
| 180 |
--replace_column 10 ### 11 ### |
| 181 |
eval explain $query; |
| 182 |
--disable_query_log |
| 183 |
send_eval $query; |
| 184 |
--enable_query_log |
| 185 |
|
| 186 |
connection server2; |
| 187 |
alter table child algorithm=copy, drop primary key; |
| 188 |
commit; |
| 189 |
|
| 190 |
connection server1; |
| 191 |
--disable_result_log |
| 192 |
--error 0,1412,1146,1296,2013 |
| 193 |
reap; |
| 194 |
--enable_result_log |
| 195 |
|
| 196 |
|
| 197 |
connection ddl; |
| 198 |
drop table child; |
| 199 |
drop table parent; |
| 200 |
|
| 201 |
drop procedure query_eq_ref_load; |
| 202 |
drop procedure query_ref_load; |
| 203 |
drop procedure query_ref_b_load; |
| 204 |
|
| 205 |
# Restore intial ndb_schema_dist_lock_wait_timeout value |
| 206 |
eval set @@global.ndb_schema_dist_lock_wait_timeout = $save_lock_wait_timeout; |