482
Find duplicate lock in tables.
484
Temporary tables are ignored here like they are ignored in
485
get_lock_data(). If we allow two opens on temporary tables later,
486
both functions should be checked.
488
@param session The current thread.
489
@param needle The table to check for duplicate lock.
490
@param haystack The list of tables to search for the dup lock.
493
This is mainly meant for MERGE tables in INSERT ... SELECT
494
situations. The 'real', underlying tables can be found only after
495
the MERGE tables are opened. This function assumes that the tables are
499
NULL No duplicate lock found.
501
!NULL First table from 'haystack' that matches a lock on 'needle'.
504
TableList *mysql_lock_have_duplicate(Session *session, TableList *needle,
507
DRIZZLE_LOCK *mylock;
511
THR_LOCK_DATA **lock_locks;
512
THR_LOCK_DATA **table_lock_data;
513
THR_LOCK_DATA **end_data;
514
THR_LOCK_DATA **lock_data2;
515
THR_LOCK_DATA **end_data2;
518
Table may not be defined for derived or view tables.
519
Table may not be part of a lock for delayed operations.
521
if (! (table= needle->table) || ! table->lock_count)
524
/* A temporary table does not have locks. */
525
if (table->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
528
/* Get command lock or LOCK TABLES lock. Maybe empty for INSERT DELAYED. */
529
if (!(mylock= session->lock))
532
/* If we have less than two tables, we cannot have duplicates. */
533
if (mylock->table_count < 2)
536
lock_locks= mylock->locks;
537
lock_tables= mylock->table;
539
/* Prepare table related variables that don't change in loop. */
540
assert((table->lock_position < mylock->table_count) &&
541
(table == lock_tables[table->lock_position]));
542
table_lock_data= lock_locks + table->lock_data_start;
543
end_data= table_lock_data + table->lock_count;
545
for (; haystack; haystack= haystack->next_global)
547
if (haystack->placeholder())
549
table2= haystack->table;
550
if (table2->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
553
/* All tables in list must be in lock. */
554
assert((table2->lock_position < mylock->table_count) &&
555
(table2 == lock_tables[table2->lock_position]));
557
for (lock_data2= lock_locks + table2->lock_data_start,
558
end_data2= lock_data2 + table2->lock_count;
559
lock_data2 < end_data2;
562
THR_LOCK_DATA **lock_data;
563
THR_LOCK *lock2= (*lock_data2)->lock;
565
for (lock_data= table_lock_data;
566
lock_data < end_data;
569
if ((*lock_data)->lock == lock2)
580
481
/** Unlock a set of external. */
582
483
static int unlock_external(Session *session, Table **table,uint32_t count)