1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
# *****************************************************************
# Test spatial index with isolation level Repeatable Read on DML
# This will also test the no phantom rows happens
# Check the COUNT(*) and SELECT results before & after COMMIT in
# the last con1 statment
# Test at con1: Global Repeatable Read con2 : Sess Read Committed
# Test at con1: Sess Repeatable Read con2 : Sess Read Committed
# *****************************************************************
--source include/have_innodb.inc
--source include/have_geometry.inc
--source include/not_embedded.inc
# Test Repeatable Read & Read committed at Global, Session levels
CREATE TABLE tab(c1 int NOT NULL PRIMARY KEY,c2 POINT NOT NULL,
c3 LINESTRING NOT NULL,c4 POLYGON NOT NULL,c5 GEOMETRY NOT NULL)
ENGINE=InnoDB;
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2);
ALTER TABLE tab ADD SPATIAL KEY idx3(c3);
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4) COMMENT 'testing spatial index on Polygon';
ALTER TABLE tab ADD SPATIAL KEY idx5(c5) COMMENT 'testing spatial index on Geometry';
INSERT INTO tab(c1,c2,c3,c4,c5)
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
# 1 record is expected
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_AsText(c4),ST_AsText(c5) FROM tab;
# Record count should be 1
SELECT COUNT(*) FROM tab;
--echo "In connection 1"
connect (con1,localhost,root,,);
connection con1;
SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SELECT @@transaction_isolation;
# Record count should be 1
SELECT COUNT(*) FROM tab;
# 1 record is expected
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_AsText(c4),ST_AsText(c5) FROM tab;
--echo "In connection 2"
connect (con2,localhost,root,,);
connection con2;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT @@transaction_isolation;
START TRANSACTION;
INSERT INTO tab(c1,c2,c3,c4,c5)
VALUES(2,ST_GeomFromText('POINT(20 20)'),ST_GeomFromText('LINESTRING(20 20,30 30,40 40)'),
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'),
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'));
SET @g1 = ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))');
SET @g2 = ST_GeomFromText('POINT(10 10)');
# Record should be updated
UPDATE tab SET C5 = ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))')
WHERE MBREquals(tab.c4, @g1) AND MBREquals(tab.c2, @g2);
--echo "In connection 1"
connection con1;
SET @g3 = ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))');
# No record is expected (No phantom row)
SELECT c1,ST_AsText(c2),ST_AsText(c4),ST_AsText(c5) FROM tab WHERE MBREquals(tab.c5, @g3);
# Record count should be 1
SELECT COUNT(*) FROM tab;
START TRANSACTION;
# Record count should be 1
SELECT COUNT(*) FROM tab;
--echo "In connection 2"
connection con2;
# Record count should be 2
SELECT COUNT(*) FROM tab;
COMMIT;
disconnect con2;
--source include/wait_until_disconnected.inc
--echo "In connection 1"
connection con1;
# Record count should be 1
SELECT COUNT(*) FROM tab;
SET @g4 = ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))');
# No records are expected (No phantom row)
SELECT ST_AsText(c5) FROM tab WHERE MBREquals(tab.c5, @g4);
COMMIT;
# The updated record is expected
SELECT ST_AsText(c5) FROM tab WHERE MBREquals(tab.c5, @g4);
# Record count should be 2
SELECT COUNT(*) FROM tab;
# 2 records are expected
SELECT c1,ST_AsText(c2),ST_AsText(c4),ST_AsText(c5) FROM tab;
disconnect con1;
--source include/wait_until_disconnected.inc
--connection default
DROP TABLE tab;
# Test Repeatable Read & Read committed at Session levels
CREATE TABLE tab(c1 int NOT NULL PRIMARY KEY,c2 POINT NOT NULL,
c3 LINESTRING NOT NULL,c4 POLYGON NOT NULL,c5 GEOMETRY NOT NULL)
ENGINE=InnoDB;
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2);
ALTER TABLE tab ADD SPATIAL KEY idx3(c3);
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4) COMMENT 'testing spatial index on Polygon';
ALTER TABLE tab ADD SPATIAL KEY idx5(c5) COMMENT 'testing spatial index on Geometry';
INSERT INTO tab(c1,c2,c3,c4,c5)
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
# 1 record is expected
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_AsText(c4),ST_AsText(c5) FROM tab;
# Record count should be 1
SELECT COUNT(*) FROM tab;
--echo "In connection 1"
connect (con1,localhost,root,,);
connection con1;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SELECT @@transaction_isolation;
# Record count should be 1
SELECT COUNT(*) FROM tab;
# 1 record is expected
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_AsText(c4),ST_AsText(c5) FROM tab;
--echo "In connection 2"
connect (con2,localhost,root,,);
connection con2;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT @@transaction_isolation;
START TRANSACTION;
INSERT INTO tab(c1,c2,c3,c4,c5)
VALUES(2,ST_GeomFromText('POINT(20 20)'),ST_GeomFromText('LINESTRING(20 20,30 30,40 40)'),
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'),
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'));
SET @g1 = ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))');
SET @g2 = ST_GeomFromText('POINT(10 10)');
# Record should be updated
UPDATE tab SET C5 = ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))')
WHERE MBREquals(tab.c4, @g1) AND MBREquals(tab.c2, @g2);
--echo "In connection 1"
connection con1;
SET @g3 = ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))');
# No record is expected (No phantom row)
SELECT c1,ST_AsText(c2),ST_AsText(c4),ST_AsText(c5) FROM tab WHERE MBREquals(tab.c5, @g3);
# Record count should be 1
SELECT COUNT(*) FROM tab;
START TRANSACTION;
# Record count should be 1
SELECT COUNT(*) FROM tab;
--echo "In connection 2"
connection con2;
# Record count should be 2
SELECT COUNT(*) FROM tab;
COMMIT;
disconnect con2;
--source include/wait_until_disconnected.inc
--echo "In connection 1"
connection con1;
# Record count should be 1
SELECT COUNT(*) FROM tab;
SET @g4 = ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))');
# No records are expected (No phantom row)
SELECT ST_AsText(c5) FROM tab WHERE MBREquals(tab.c5, @g4);
COMMIT;
# The updated record is expected
SELECT ST_AsText(c5) FROM tab WHERE MBREquals(tab.c5, @g4);
# Record count should be 2
SELECT COUNT(*) FROM tab;
# 2 records are expected
SELECT c1,ST_AsText(c2),ST_AsText(c4),ST_AsText(c5) FROM tab;
disconnect con1;
--source include/wait_until_disconnected.inc
--connection default
DROP TABLE tab;
|