Skip to content

Commit a94ba10

Browse files
Fix for BDB and LOCK TABLES
1 parent 3876d83 commit a94ba10

15 files changed

Lines changed: 158 additions & 77 deletions

File tree

Docs/manual.texi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22511,6 +22511,9 @@ locks while the thread is waiting for the @code{WRITE} lock. You should only
2251122511
use @code{LOW_PRIORITY WRITE} locks if you are sure that there will
2251222512
eventually be a time when no threads will have a @code{READ} lock.
2251322513

22514+
@code{LOCK TABLES} and @code{UNLOCK TABLES} both commits any active
22515+
transactions.
22516+
2251422517
When you use @code{LOCK TABLES}, you must lock all tables that you are
2251522518
going to use and you must use the same alias that you are going to use
2251622519
in your queries! If you are using a table multiple times in a query
@@ -43940,20 +43943,24 @@ not yet 100% confident in this code.
4394043943
@appendixsubsec Changes in release 3.23.38
4394143944
@itemize @bullet
4394243945
@item
43946+
Lots of portability fixes for InnoDB.
43947+
@item
4394343948
Changed optimizer so that queries like
4394443949
@code{SELECT * FROM table_name,table_name2 ... ORDER BY key_part1 LIMIT #}
4394543950
will use index on @code{key_part1} instead of @code{filesort}.
4394643951
@item
4394743952
Fixed bug when doing
4394843953
@code{LOCK TABLE to_table WRITE,...; INSERT INTO to_table... SELECT ...}
4394943954
when to_table was empty.
43955+
@item
43956+
Fixed bug with @code{LOCK TABLE} and BDB tables.
4395043957
@end itemize
4395143958

4395243959
@node News-3.23.37, News-3.23.36, News-3.23.38, News-3.23.x
4395343960
@appendixsubsec Changes in release 3.23.37
4395443961
@itemize @bullet
4395543962
@item
43956-
Fixed a bug when using MATCH in HAVING clause.
43963+
Fixed a bug when using @code{MATCH} in @code{HAVING} clause.
4395743964
@item
4395843965
Fixed a bug when using @code{HEAP} tables with @code{LIKE}.
4395943966
@item
@@ -43977,7 +43984,7 @@ with @code{SET SQL_SLAVE_SKIP_COUNTER=1; SLAVE START} after a manual sanity
4397743984
check/correction of data integrity
4397843985
@item
4397943986
Fixed bug that erroneously logged a drop of internal temporary table
43980-
on thread termination to the binary log - bug affected replication
43987+
on thread termination to the binary log - bug affected replication
4398143988
@item
4398243989
Fixed a bug in @code{REGEXP()} on 64-bit machines.
4398343990
@item

innobase/ib_config.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

innobase/ib_config.h.in

Lines changed: 0 additions & 30 deletions
This file was deleted.

myisam/mi_locking.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,10 @@ int _mi_readinfo(register MI_INFO *info, int lock_type, int check_keybuffer)
335335
int _mi_writeinfo(register MI_INFO *info, uint operation)
336336
{
337337
int error,olderror;
338-
MYISAM_SHARE *share;
338+
MYISAM_SHARE *share=info->s;
339339
DBUG_ENTER("_mi_writeinfo");
340340

341341
error=0;
342-
share=info->s;
343342
if (share->r_locks == 0 && share->w_locks == 0)
344343
{
345344
olderror=my_errno; /* Remember last error */
@@ -368,7 +367,7 @@ int _mi_writeinfo(register MI_INFO *info, uint operation)
368367
{
369368
share->changed= 1; /* Mark keyfile changed */
370369
}
371-
DBUG_RETURN(error);
370+
DBUG_RETURN(error);
372371
} /* _mi_writeinfo */
373372

374373

mysql-test/r/bdb.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,20 @@ a 1
492492
a 2
493493
MIN(B) MAX(b)
494494
1 1
495+
id
496+
0
497+
1
498+
2
499+
id
500+
0
501+
1
502+
2
503+
id
504+
0
505+
1
506+
2
507+
id id3
508+
0 0
509+
1 1
510+
2 2
511+
100 2

mysql-test/r/innodb.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,20 @@ a
449449
1
450450
table type possible_keys key key_len ref rows Extra
451451
t1 range PRIMARY PRIMARY 4 NULL 1 where used
452+
id
453+
0
454+
1
455+
2
456+
id
457+
0
458+
1
459+
2
460+
id
461+
0
462+
1
463+
2
464+
id id3
465+
0 0
466+
1 1
467+
2 2
468+
100 2

mysql-test/t/bdb.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,3 +678,30 @@ CREATE TABLE t1 (
678678
INSERT INTO t1 VALUES (1, 1);
679679
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
680680
drop table t1;
681+
682+
#
683+
# Test problem with BDB and lock tables with duplicate write.
684+
#
685+
686+
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=bdb;
687+
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
688+
LOCK TABLES t1 WRITE;
689+
--error 690
690+
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
691+
select id from t1;
692+
select id from t1;
693+
UNLOCK TABLES;
694+
DROP TABLE t1;
695+
696+
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=bdb;
697+
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
698+
LOCK TABLES t1 WRITE;
699+
begin;
700+
--error 690
701+
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
702+
select id from t1;
703+
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
704+
commit;
705+
select id,id3 from t1;
706+
UNLOCK TABLES;
707+
DROP TABLE t1;

mysql-test/t/innodb.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,30 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h
429429
insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
430430
explain select * from t1 where a > 0 and a < 50;
431431
drop table t1;
432+
433+
#
434+
# Test lock tables
435+
#
436+
437+
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=innodb;
438+
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
439+
LOCK TABLES t1 WRITE;
440+
--error 690
441+
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
442+
select id from t1;
443+
select id from t1;
444+
UNLOCK TABLES;
445+
DROP TABLE t1;
446+
447+
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=innodb;
448+
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
449+
LOCK TABLES t1 WRITE;
450+
begin;
451+
--error 690
452+
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
453+
select id from t1;
454+
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
455+
commit;
456+
select id,id3 from t1;
457+
UNLOCK TABLES;
458+
DROP TABLE t1;

sql-bench/test-insert.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ $opt_read_key_loop_count=$opt_loop_count;
3939
chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
4040
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
4141

42-
if ($opt_loop_count < 256)
43-
{
44-
$opt_loop_count=256; # Some tests must have some data to work!
45-
}
46-
4742
if ($opt_small_test)
4843
{
4944
$opt_loop_count/=100;
@@ -62,6 +57,13 @@ elsif ($opt_small_key_tables)
6257
$many_keys_loop_count/=10;
6358
}
6459

60+
if ($opt_loop_count < 100)
61+
{
62+
$opt_loop_count=100; # Some tests must have some data to work!
63+
}
64+
$range_loop_count=min($opt_loop_count,$range_loop_count);
65+
66+
6567
print "Testing the speed of inserting data into 1 table and do some selects on it.\n";
6668
print "The tests are done with a table that has $opt_loop_count rows.\n\n";
6769

sql/ha_berkeley.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@
4141
from the updated tables.
4242
4343
Testing of:
44-
- LOCK TABLES
4544
- Mark tables that participate in a transaction so that they are not
4645
closed during the transaction. We need to test what happens if
47-
MySQL closes a table that is updated by a not commit transaction.
46+
MySQL closes a table that is updated by a not commited transaction.
4847
*/
4948

5049

@@ -1701,12 +1700,35 @@ int ha_berkeley::external_lock(THD *thd, int lock_type)
17011700
DBUG_PRINT("trans",("commiting non-updating transaction"));
17021701
error=txn_commit((DB_TXN*) thd->transaction.stmt.bdb_tid,0);
17031702
thd->transaction.stmt.bdb_tid=0;
1703+
transaction=0;
17041704
}
17051705
}
17061706
}
17071707
DBUG_RETURN(error);
17081708
}
17091709

1710+
1711+
/*
1712+
When using LOCK TABLE's external_lock is only called when the actual
1713+
TABLE LOCK is done.
1714+
Under LOCK TABLES, each used tables will force a call to start_stmt.
1715+
*/
1716+
1717+
int ha_berkeley::start_stmt(THD *thd)
1718+
{
1719+
int error=0;
1720+
DBUG_ENTER("ha_berkeley::start_stmt");
1721+
if (!thd->transaction.stmt.bdb_tid)
1722+
{
1723+
error=txn_begin(db_env, (DB_TXN*) thd->transaction.all.bdb_tid,
1724+
(DB_TXN**) &thd->transaction.stmt.bdb_tid,
1725+
0);
1726+
transaction= (DB_TXN*) thd->transaction.stmt.bdb_tid;
1727+
}
1728+
DBUG_RETURN(error);
1729+
}
1730+
1731+
17101732
/*
17111733
The idea with handler::store_lock() is the following:
17121734

0 commit comments

Comments
 (0)