~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/lock.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 06:24:48 UTC
  • mfrom: (1220.1.15 staging)
  • Revision ID: brian@gaz-20091118062448-o36lo3yv81sc6u9z
Merge Brian + Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
478
478
}
479
479
 
480
480
 
481
 
/**
482
 
  Find duplicate lock in tables.
483
 
 
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.
487
 
 
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.
491
 
 
492
 
  @note
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
496
 
    already locked.
497
 
 
498
 
  @retval
499
 
    NULL    No duplicate lock found.
500
 
  @retval
501
 
    !NULL   First table from 'haystack' that matches a lock on 'needle'.
502
 
*/
503
 
 
504
 
TableList *mysql_lock_have_duplicate(Session *session, TableList *needle,
505
 
                                      TableList *haystack)
506
 
{
507
 
  DRIZZLE_LOCK            *mylock;
508
 
  Table                 **lock_tables;
509
 
  Table                 *table;
510
 
  Table                 *table2;
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;
516
 
 
517
 
  /*
518
 
    Table may not be defined for derived or view tables.
519
 
    Table may not be part of a lock for delayed operations.
520
 
  */
521
 
  if (! (table= needle->table) || ! table->lock_count)
522
 
    goto end;
523
 
 
524
 
  /* A temporary table does not have locks. */
525
 
  if (table->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
526
 
    goto end;
527
 
 
528
 
  /* Get command lock or LOCK TABLES lock. Maybe empty for INSERT DELAYED. */
529
 
  if (!(mylock= session->lock))
530
 
    goto end;
531
 
 
532
 
  /* If we have less than two tables, we cannot have duplicates. */
533
 
  if (mylock->table_count < 2)
534
 
    goto end;
535
 
 
536
 
  lock_locks=  mylock->locks;
537
 
  lock_tables= mylock->table;
538
 
 
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;
544
 
 
545
 
  for (; haystack; haystack= haystack->next_global)
546
 
  {
547
 
    if (haystack->placeholder())
548
 
      continue;
549
 
    table2= haystack->table;
550
 
    if (table2->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
551
 
      continue;
552
 
 
553
 
    /* All tables in list must be in lock. */
554
 
    assert((table2->lock_position < mylock->table_count) &&
555
 
                (table2 == lock_tables[table2->lock_position]));
556
 
 
557
 
    for (lock_data2=  lock_locks + table2->lock_data_start,
558
 
           end_data2= lock_data2 + table2->lock_count;
559
 
         lock_data2 < end_data2;
560
 
         lock_data2++)
561
 
    {
562
 
      THR_LOCK_DATA **lock_data;
563
 
      THR_LOCK *lock2= (*lock_data2)->lock;
564
 
 
565
 
      for (lock_data= table_lock_data;
566
 
           lock_data < end_data;
567
 
           lock_data++)
568
 
      {
569
 
        if ((*lock_data)->lock == lock2)
570
 
          return haystack;
571
 
      }
572
 
    }
573
 
  }
574
 
 
575
 
 end:
576
 
  return NULL;
577
 
}
578
 
 
579
 
 
580
481
/** Unlock a set of external. */
581
482
 
582
483
static int unlock_external(Session *session, Table **table,uint32_t count)
652
553
    Table *table;
653
554
    enum thr_lock_type lock_type;
654
555
 
655
 
    if ((table=table_ptr[i])->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
 
556
    if (table_ptr[i]->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE)
656
557
      continue;
 
558
    table= table_ptr[i];
657
559
    lock_type= table->reginfo.lock_type;
658
560
    assert (lock_type != TL_WRITE_DEFAULT);
659
561
    if (lock_type >= TL_WRITE_ALLOW_WRITE)