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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
|
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- test DDL Table Lock mode
call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1);
maximumdisplaywidth 2000;
CREATE PROCEDURE WAIT_FOR_POST_COMMIT() DYNAMIC RESULT SETS 0 LANGUAGE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.T_Access.waitForPostCommitToFinish' PARAMETER STYLE JAVA;
-- create tables with different lock modes
drop table default1;
create table default1(c1 int);
drop table row1;
create table row1(c1 int);
alter table row1 locksize row;
drop table table1;
create table table1(c1 int);
alter table table1 locksize table;
-- verify that views have table lock mode of 'R' (ignored)
create view v1 as select * from table1;
select tablename, lockgranularity from sys.systables
where tablename = 'V1';
drop view v1;
-- verify that system tables have lock mode of 'R'
select tablename, lockgranularity from sys.systables
where tablename = 'SYSTABLES';
-- READ COMMITTED tests
call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1);
maximumdisplaywidth 2000;
set current isolation = CS;
-- all selects should be row locked except for table1
select * from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all updates should be row locked except for table1
update default1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update default1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- all inserts should be row locked except for table1
insert into default1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into row1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into table1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all deletes should be row locked except for table1
delete from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from default1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
-- REPEATABLE READ tests
-- repeatable read works the same as serializable when no indexes are involved
-- create tables with different lock modes
drop table default1;
create table default1(c1 int);
drop table row1;
create table row1(c1 int);
alter table row1 locksize row;
drop table table1;
create table table1(c1 int);
alter table table1 locksize table;
set current isolation RS;
-- all selects should be row locked except for table1
select * from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all updates should be row locked except for table1
update default1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update default1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- all inserts should be row locked except for table1
insert into default1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into row1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into table1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all deletes should be row locked except for table1
delete from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from default1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
-- alter table
-- first set to same value (stupid test)
alter table default1 locksize row;
alter table row1 locksize row;
alter table table1 locksize table;
select tablename, lockGranularity from sys.systables
where tablename in ('DEFAULT1', 'ROW1', 'TABLE1')
order by tablename;
-- set to opposite value
alter table default1 locksize table;
alter table row1 locksize table;
alter table table1 locksize row;
select tablename, lockGranularity from sys.systables
where tablename in ('DEFAULT1', 'ROW1', 'TABLE1')
order by tablename;
-- READ UNCOMMITTED tests
-- create tables with different lock modes
drop table default1;
create table default1(c1 int);
drop table row1;
create table row1(c1 int);
alter table row1 locksize row;
drop table table1;
create table table1(c1 int);
alter table table1 locksize table;
set isolation = read uncommitted;
-- all selects should be row locked except for table1
select * from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all updates should be row locked except for table1
update default1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update default1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- all inserts should be row locked except for table1
insert into default1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into row1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into table1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all deletes should be row locked except for table1
delete from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from default1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
-- alter table
-- first set to same value (stupid test)
alter table default1 locksize row;
alter table row1 locksize row;
alter table table1 locksize table;
select tablename, lockGranularity from sys.systables
where tablename in ('DEFAULT1', 'ROW1', 'TABLE1')
order by tablename;
-- set to opposite value
alter table default1 locksize table;
alter table row1 locksize table;
alter table table1 locksize row;
select tablename, lockGranularity from sys.systables
where tablename in ('DEFAULT1', 'ROW1', 'TABLE1')
order by tablename;
-- SERIALIZABLE tests
-- create tables with different lock modes
drop table default1;
create table default1(c1 int);
drop table row1;
create table row1(c1 int);
alter table row1 locksize row;
drop table table1;
create table table1(c1 int);
alter table table1 locksize table;
set isolation serializable;
-- all selects should be table locked since no where clause
select * from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all updates should be table locked
-- (No indexes, so will always do table scan)
update default1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update default1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- all inserts should be row locked except for table1
insert into default1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into row1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into table1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- scans for all deletes should be table locked
-- (No indexes, so will always do table scan)
delete from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from default1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
-- alter table
-- first set to same value (stupid test)
alter table default1 locksize row;
alter table row1 locksize row;
alter table table1 locksize table;
select tablename, lockGranularity from sys.systables
where tablename in ('DEFAULT1', 'ROW1', 'TABLE1')
order by tablename;
-- set to opposite value
alter table default1 locksize table;
alter table row1 locksize table;
alter table table1 locksize row;
select tablename, lockGranularity from sys.systables
where tablename in ('DEFAULT1', 'ROW1', 'TABLE1')
order by tablename;
set isolation read committed;
-- verify lock granularity changed for selects
select * from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
select * from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- verify lock granularity changed for updates
update default1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update default1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update row1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
update table1 set c1 = 1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- verify lock granularity changed for inserts
insert into default1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into row1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
insert into table1 values 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
-- verify lock granularity changed for deletes
delete from default1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from default1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from row1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
delete from table1 where c1 = 1;
values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();
CALL WAIT_FOR_POST_COMMIT();
-- bug 3819; delete from table would first
-- end up getting an IX lock on table then
-- an X lock on table; this can lead to
-- deadlocks with multiple threads doing
-- delete from table. fix is to choose
-- row locking for deletes/updates in *all*
-- cases; this would result in an IX lock
-- on the table. means more locking but
-- increased concurrency.
insert into default1 values (1);
insert into default1 values (2);
select * from default1 order by c1;
set isolation to CURSOR STABILITY;
autocommit off;
delete from default1;
-- should see only one lock; earlier used to
-- see 2, one IX and one for X.
select count(*)
from syscs_diag.lock_table
where tablename = 'DEFAULT1' and type = 'TABLE';
commit;
-- cleanup
drop procedure WAIT_FOR_POST_COMMIT;
drop table default1;
drop table row1;
drop table table1;
|