| 1 |
-- source include/have_ndb.inc |
| 2 |
|
| 3 |
# store start value |
| 4 |
SET @global_start_value = @@global.ndb_optimized_node_selection; |
| 5 |
SELECT @global_start_value; |
| 6 |
|
| 7 |
# max value |
| 8 |
set session ndb_optimized_node_selection=3; |
| 9 |
show variables like 'ndb_optimized_node_selection'; |
| 10 |
|
| 11 |
# min value |
| 12 |
set session ndb_optimized_node_selection=0; |
| 13 |
show variables like 'ndb_optimized_node_selection'; |
| 14 |
|
| 15 |
# out of range |
| 16 |
set session ndb_optimized_node_selection=4; |
| 17 |
show variables like 'ndb_optimized_node_selection'; |
| 18 |
|
| 19 |
# global |
| 20 |
set global ndb_optimized_node_selection=1; |
| 21 |
show variables like 'ndb_optimized_node_selection'; |
| 22 |
|
| 23 |
# check it |
| 24 |
--connect (another_con, localhost, root,,) |
| 25 |
--connection another_con |
| 26 |
show variables like 'ndb_optimized_node_selection'; |
| 27 |
|
| 28 |
--connection default |
| 29 |
# reset |
| 30 |
SET @@global.ndb_optimized_node_selection = @global_start_value; |
| 31 |
SELECT @@global.ndb_optimized_node_selection; |
| 32 |
|
| 33 |
--echo Test behaviours within each variant |
| 34 |
|
| 35 |
--let $dist=0 |
| 36 |
|
| 37 |
while ($dist < 3) |
| 38 |
{ |
| 39 |
if ($dist == 0) |
| 40 |
{ |
| 41 |
--let $distname=READ PRIMARY |
| 42 |
create table t1 (a int primary key, b int) engine=ndb comment="NDB_TABLE=READ_BACKUP=0"; |
| 43 |
} |
| 44 |
if ($dist == 1) |
| 45 |
{ |
| 46 |
--let $distname=READ BACKUP |
| 47 |
create table t1 (a int primary key, b int) engine=ndb comment="NDB_TABLE=READ_BACKUP=1"; |
| 48 |
} |
| 49 |
if ($dist == 2) |
| 50 |
{ |
| 51 |
--let $distname=FULLY REPLICATED |
| 52 |
create table t1 (a int primary key, b int) engine=ndb comment="NDB_TABLE=FULLY_REPLICATED=1"; |
| 53 |
} |
| 54 |
|
| 55 |
insert into t1 values (0,0), (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9); |
| 56 |
|
| 57 |
create table basecounts (node_id int primary key, transcount int) engine=innodb; |
| 58 |
|
| 59 |
--let $val=0 |
| 60 |
|
| 61 |
while ($val < 4) |
| 62 |
{ |
| 63 |
--eval set ndb_optimized_node_selection=$val |
| 64 |
show variables like 'ndb_optimized_node_selection'; |
| 65 |
|
| 66 |
--let $case=0 |
| 67 |
while ($case < 4) |
| 68 |
{ |
| 69 |
--disable_query_log |
| 70 |
--disable_result_log |
| 71 |
# Initial query ideally doing any e.g. stats fetches |
| 72 |
select * from test.t1 where a=0; |
| 73 |
|
| 74 |
delete from basecounts; |
| 75 |
insert into basecounts |
| 76 |
select node_id, sum(val) |
| 77 |
from ndbinfo.counters |
| 78 |
where counter_name="TRANSACTIONS" |
| 79 |
group by node_id; |
| 80 |
|
| 81 |
--let $iter=100 |
| 82 |
--let $errbound=$iter/10 |
| 83 |
--let $rpt=$iter |
| 84 |
while ($rpt) |
| 85 |
{ |
| 86 |
if ($case == 0) |
| 87 |
{ |
| 88 |
--let $casename=Hinted autocommit select by pk |
| 89 |
select * from test.t1 where a=0; |
| 90 |
} |
| 91 |
if ($case == 1) |
| 92 |
{ |
| 93 |
--let $casename=Unhinted table scan |
| 94 |
begin; |
| 95 |
select * from test.t1; |
| 96 |
select * from test.t1 where a=0; |
| 97 |
rollback; |
| 98 |
} |
| 99 |
if ($case == 2) |
| 100 |
{ |
| 101 |
--let $casename=Autocommit update by pk |
| 102 |
update test.t1 set b=2 where a=0; |
| 103 |
} |
| 104 |
if ($case == 3) |
| 105 |
{ |
| 106 |
--let $casename=Unhinted table scan on new connection |
| 107 |
connect(testcon, localhost, root,,); |
| 108 |
--connection testcon |
| 109 |
--eval set ndb_optimized_node_selection=$val; |
| 110 |
begin; |
| 111 |
select * from test.t1; |
| 112 |
select * from test.t1 where a=0; |
| 113 |
rollback; |
| 114 |
--connection default |
| 115 |
disconnect testcon; |
| 116 |
} |
| 117 |
--dec $rpt |
| 118 |
} |
| 119 |
--enable_result_log |
| 120 |
|
| 121 |
# Query here works out per-node TRANSACTIONS count diff around ops |
| 122 |
# That shows the 'hinting' footprint |
| 123 |
# if statement is used to map loosely to ALL/HALF/NONE to handle |
| 124 |
# non determinism due to other activity in the cluster during the |
| 125 |
# test. |
| 126 |
--echo $distname o-n-s $val case $casename |
| 127 |
eval select x.node_id, |
| 128 |
if (x.transcount >= ($iter-($errbound)), "ALL", |
| 129 |
if (x.transcount <= ($errbound), "NONE", |
| 130 |
if (x.transcount BETWEEN (($iter/2)-($errbound)) |
| 131 |
AND (($iter/2)+($errbound)), |
| 132 |
"HALF", "ERROR"))) as balance |
| 133 |
from ( |
| 134 |
select a.node_id, b.transcount - a.transcount as transcount |
| 135 |
from basecounts a |
| 136 |
join |
| 137 |
(select node_id, sum(val) as transcount |
| 138 |
from ndbinfo.counters |
| 139 |
where counter_name="TRANSACTIONS" |
| 140 |
group by node_id) b |
| 141 |
on a.node_id = b.node_id) x; |
| 142 |
|
| 143 |
--enable_query_log |
| 144 |
|
| 145 |
--inc $case |
| 146 |
} |
| 147 |
|
| 148 |
--inc $val |
| 149 |
} |
| 150 |
drop table basecounts; |
| 151 |
drop table t1; |
| 152 |
|
| 153 |
--inc $dist |
| 154 |
} |