Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
73907f53
Commit
73907f53
authored
Feb 20, 2006
by
ingo@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BUG#5390 - problems with merge tables
Merge from 4.1
parent
e0098885
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
95 deletions
+71
-95
sql/lock.cc
sql/lock.cc
+65
-84
sql/table.h
sql/table.h
+6
-11
No files found.
sql/lock.cc
View file @
73907f53
...
@@ -499,112 +499,91 @@ MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b)
...
@@ -499,112 +499,91 @@ MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b)
NOTE
NOTE
This is mainly meant for MERGE tables in INSERT ... SELECT
This is mainly meant for MERGE tables in INSERT ... SELECT
situations. The 'real', underlying tables can be found only after
situations. The 'real', underlying tables can be found only after
the table is opened. The easier way is to check this after the
the MERGE tables are opened. This function assumes that the tables are
tables are locked.
already locked.
Temporary tables are ignored here like they are ignored in
get_lock_data(). If we allow two opens on temporary tables later,
both functions should be checked.
RETURN
RETURN
1 A table from 'tables' matches a lock on 'table'.
NULL No duplicate lock found.
0 No duplicate lock is present.
! NULL First table from 'haystack' that matches a lock on 'needle'.
-1 Error.
*/
*/
TABLE_LIST
*
mysql_lock_have_duplicate
(
THD
*
thd
,
TABLE_LIST
*
needle
,
TABLE_LIST
*
mysql_lock_have_duplicate
(
THD
*
thd
,
TABLE_LIST
*
needle
,
TABLE_LIST
*
haystack
)
TABLE_LIST
*
haystack
)
{
{
uint
count
;
MYSQL_LOCK
*
mylock
;
uint
dup_pos
;
TABLE
**
lock_tables
;
TABLE
*
write_lock_used
;
/* dummy */
TABLE
*
table
;
TABLE
**
tables1
;
TABLE
*
table2
;
TABLE
**
tables2
;
THR_LOCK_DATA
**
lock_locks
;
TABLE
**
table_ptr
;
THR_LOCK_DATA
**
table_lock_data
;
TABLE_LIST
*
tlist_ptr
;
THR_LOCK_DATA
**
end_data
;
MYSQL_LOCK
*
sql_lock1
;
MYSQL_LOCK
*
sql_lock2
;
THR_LOCK_DATA
**
lock_data1
;
THR_LOCK_DATA
**
end_data1
;
THR_LOCK_DATA
**
lock_data2
;
THR_LOCK_DATA
**
lock_data2
;
THR_LOCK_DATA
**
end_data2
;
THR_LOCK_DATA
**
end_data2
;
THR_LOCK
*
lock1
;
DBUG_ENTER
(
"mysql_lock_have_duplicate"
);
DBUG_ENTER
(
"mysql_lock_have_duplicate"
);
/* Table may not be defined for derived or view tables. */
/* Table may not be defined for derived or view tables. */
if
(
!
needle
->
table
)
if
(
!
(
table
=
needle
->
table
)
)
DBUG_RETURN
(
NULL
)
;
goto
end
;
/* Get lock(s) for needle. */
/* A temporary table does not have locks. */
tables1
=
&
needle
->
table
;
if
(
table
->
s
->
tmp_table
==
TMP_TABLE
)
if
(
!
(
sql_lock1
=
get_lock_data
(
thd
,
tables1
,
1
,
1
,
&
write_lock_used
)))
goto
end
;
goto
err0
;
/* Get command lock or LOCK TABLES lock. Maybe empty for INSERT DELAYED. */
/* Count real tables in list. */
if
(
!
(
mylock
=
thd
->
lock
?
thd
->
lock
:
thd
->
locked_tables
))
count
=
0
;
goto
end
;
for
(
tlist_ptr
=
haystack
;
tlist_ptr
;
tlist_ptr
=
tlist_ptr
->
next_global
)
if
(
!
tlist_ptr
->
placeholder
()
&&
!
tlist_ptr
->
schema_table
)
/* If we have less than two tables, we cannot have duplicates. */
count
++
;
if
(
mylock
->
table_count
<
2
)
/* Allocate a table array. */
goto
end
;
if
(
!
(
tables2
=
(
TABLE
**
)
sql_alloc
(
sizeof
(
TABLE
*
)
*
count
)))
goto
err1
;
lock_locks
=
mylock
->
locks
;
table_ptr
=
tables2
;
lock_tables
=
mylock
->
table
;
/* Assign table pointers. */
for
(
tlist_ptr
=
haystack
;
tlist_ptr
;
tlist_ptr
=
tlist_ptr
->
next_global
)
/* Prepare table related variables that don't change in loop. */
if
(
!
tlist_ptr
->
placeholder
()
&&
!
tlist_ptr
->
schema_table
)
DBUG_ASSERT
(
table
==
lock_tables
[
table
->
lock_position
]);
*
(
table_ptr
++
)
=
tlist_ptr
->
table
;
table_lock_data
=
lock_locks
+
table
->
lock_data_start
;
/* Get lock(s) for haystack. */
end_data
=
table_lock_data
+
table
->
lock_count
;
if
(
!
(
sql_lock2
=
get_lock_data
(
thd
,
tables2
,
count
,
1
,
&
write_lock_used
)))
goto
err1
;
for
(;
haystack
;
haystack
=
haystack
->
next_global
)
/* Initialize duplicate position to an impossible value. */
dup_pos
=
UINT_MAX
;
/*
Find a duplicate lock.
In case of merge tables, sql_lock1 can have more than 1 lock.
*/
for
(
lock_data1
=
sql_lock1
->
locks
,
end_data1
=
lock_data1
+
sql_lock1
->
lock_count
;
lock_data1
<
end_data1
;
lock_data1
++
)
{
{
lock1
=
(
*
lock_data1
)
->
lock
;
if
(
haystack
->
placeholder
()
||
haystack
->
schema_table
)
for
(
lock_data2
=
sql_lock2
->
locks
,
continue
;
end_data2
=
lock_data2
+
sql_lock2
->
lock_count
;
table2
=
haystack
->
table
;
if
(
table2
->
s
->
tmp_table
==
TMP_TABLE
)
continue
;
/* All tables in list must be in lock. */
DBUG_ASSERT
(
table2
==
lock_tables
[
table2
->
lock_position
]);
for
(
lock_data2
=
lock_locks
+
table2
->
lock_data_start
,
end_data2
=
lock_data2
+
table2
->
lock_count
;
lock_data2
<
end_data2
;
lock_data2
<
end_data2
;
lock_data2
++
)
lock_data2
++
)
{
{
if
((
*
lock_data2
)
->
lock
==
lock1
)
THR_LOCK_DATA
**
lock_data
;
{
THR_LOCK
*
lock2
=
(
*
lock_data2
)
->
lock
;
DBUG_PRINT
(
"ingo"
,
(
"duplicate lock found"
));
/* Change duplicate position to the real value. */
dup_pos
=
lock_data2
-
sql_lock2
->
locks
;
goto
end
;
}
}
}
end:
for
(
lock_data
=
table_lock_data
;
tlist_ptr
=
NULL
;
/* In case that no duplicate was found. */
lock_data
<
end_data
;
if
(
dup_pos
!=
UINT_MAX
)
lock_data
++
)
{
{
/* Duplicate found. Search the matching TABLE_LIST object. */
if
((
*
lock_data
)
->
lock
==
lock2
)
count
=
0
;
for
(
tlist_ptr
=
haystack
;
tlist_ptr
;
tlist_ptr
=
tlist_ptr
->
next_global
)
{
{
if
(
!
tlist_ptr
->
placeholder
()
&&
!
tlist_ptr
->
schema_table
)
DBUG_PRINT
(
"info"
,
(
"haystack match: '%s'"
,
haystack
->
table_name
));
{
DBUG_RETURN
(
haystack
);
count
+=
tlist_ptr
->
table
->
file
->
lock_count
();
if
(
count
>
dup_pos
)
break
;
}
}
}
}
}
}
my_free
((
gptr
)
sql_lock2
,
MYF
(
0
));
}
my_free
((
gptr
)
sql_lock1
,
MYF
(
0
));
DBUG_RETURN
(
tlist_ptr
);
end:
DBUG_PRINT
(
"info"
,
(
"no duplicate found"
));
err1:
DBUG_RETURN
(
NULL
);
my_free
((
gptr
)
sql_lock1
,
MYF
(
0
));
err0:
/* This non-null but special value indicates error, if caller cares. */
DBUG_RETURN
(
needle
);
}
}
...
@@ -693,6 +672,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
...
@@ -693,6 +672,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
for
(
i
=
0
;
i
<
count
;
i
++
)
for
(
i
=
0
;
i
<
count
;
i
++
)
{
{
TABLE
*
table
;
TABLE
*
table
;
enum
thr_lock_type
lock_type
;
if
((
table
=
table_ptr
[
i
])
->
s
->
tmp_table
==
TMP_TABLE
)
if
((
table
=
table_ptr
[
i
])
->
s
->
tmp_table
==
TMP_TABLE
)
continue
;
continue
;
lock_type
=
table
->
reginfo
.
lock_type
;
lock_type
=
table
->
reginfo
.
lock_type
;
...
...
sql/table.h
View file @
73907f53
...
@@ -235,14 +235,9 @@ struct st_table {
...
@@ -235,14 +235,9 @@ struct st_table {
timestamp_auto_set_type
timestamp_field_type
;
timestamp_auto_set_type
timestamp_field_type
;
table_map
map
;
/* ID bit of table (1,2,4,8,16...) */
table_map
map
;
/* ID bit of table (1,2,4,8,16...) */
uint
next_number_index
;
uint
blob_ptr_size
;
/* 4 or 8 */
uint
next_number_key_offset
;
uint
lock_position
;
/* Position in MYSQL_LOCK.table */
uint
lock_position
;
/* Position in MYSQL_LOCK.table */
uint
lock_data_start
;
/* Start pos. in MYSQL_LOCK.locks */
uint
lock_data_start
;
/* Start pos. in MYSQL_LOCK.locks */
uint
lock_count
;
/* Number of locks */
uint
lock_count
;
/* Number of locks */
int
current_lock
;
/* Type of lock on table */
enum
tmp_table_type
tmp_table
;
uint
tablenr
,
used_fields
;
uint
tablenr
,
used_fields
;
uint
temp_pool_slot
;
/* Used by intern temp tables */
uint
temp_pool_slot
;
/* Used by intern temp tables */
uint
status
;
/* What's in record[0] */
uint
status
;
/* What's in record[0] */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment