~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

merged with latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
377
377
        global read lock won't sneak in.
378
378
      */
379
379
      if (table->reginfo.lock_type < TL_WRITE_ALLOW_WRITE)
380
 
        table->getMutableShare()->version= refresh_version;
 
380
        table->getMutableShare()->refreshVersion();
381
381
    }
382
382
  }
383
383
 
968
968
    This also allows us to assume that no other connection will sneak in
969
969
    before we will get table-level lock on this table.
970
970
  */
971
 
  share->version=0;
 
971
  share->resetVersion();
972
972
  table->in_use = this;
973
973
 
974
974
  if (link_in)
1269
1269
      if (flags & DRIZZLE_LOCK_IGNORE_FLUSH)
1270
1270
      {
1271
1271
        /* Force close at once after usage */
1272
 
        version= table->getShare()->version;
 
1272
        version= table->getShare()->getVersion();
1273
1273
        continue;
1274
1274
      }
1275
1275
 
1403
1403
  table->reginfo.lock_type= TL_READ; /* Assume read */
1404
1404
 
1405
1405
reset:
1406
 
  assert(table->getShare()->ref_count > 0 || table->getShare()->tmp_table != message::Table::STANDARD);
 
1406
  assert(table->getShare()->getTableCount() > 0 || table->getShare()->tmp_table != message::Table::STANDARD);
1407
1407
 
1408
1408
  if (lex->need_correct_ident())
1409
1409
    table->alias_name_used= my_strcasecmp(table_alias_charset,
1858
1858
*/
1859
1859
 
1860
1860
 
1861
 
Table *drop_locked_tables(Session *session,const char *db, const char *table_name)
 
1861
Table *drop_locked_tables(Session *session, const char *db, const char *table_name)
1862
1862
{
1863
1863
  Table *table,*next,**prev, *found= 0;
1864
1864
  prev= &session->open_tables;
1975
1975
  {
1976
1976
    if (error == 7)                             // Table def changed
1977
1977
    {
1978
 
      share->version= 0;                        // Mark share as old
 
1978
      share->resetVersion();                        // Mark share as old
1979
1979
      if (discover_retry_count++)               // Retry once
1980
1980
        goto err;
1981
1981
 
1998
1998
        To avoid deadlock, only wait for release if no one else is
1999
1999
        using the share.
2000
2000
      */
2001
 
      if (share->ref_count != 1)
 
2001
      if (share->getTableCount() != 1)
2002
2002
        goto err;
2003
2003
      /* Free share and wait until it's released by all threads */
2004
2004
      TableShare::release(share);
2493
2493
  uint32_t cached_field_index= *cached_field_index_ptr;
2494
2494
 
2495
2495
  /* We assume here that table->field < NO_CACHED_FIELD_INDEX = UINT_MAX */
2496
 
  if (cached_field_index < table->getShare()->fields &&
 
2496
  if (cached_field_index < table->getShare()->sizeFields() &&
2497
2497
      !my_strcasecmp(system_charset_info,
2498
 
                     table->field[cached_field_index]->field_name, name))
2499
 
    field_ptr= table->field + cached_field_index;
 
2498
                     table->getField(cached_field_index)->field_name, name))
 
2499
  {
 
2500
    field_ptr= table->getFields() + cached_field_index;
 
2501
  }
2500
2502
  else if (table->getShare()->name_hash.records)
2501
2503
  {
2502
2504
    field_ptr= (Field**) hash_search(&table->getShare()->name_hash, (unsigned char*) name,
2507
2509
        field_ptr points to field in TableShare. Convert it to the matching
2508
2510
        field in table
2509
2511
      */
2510
 
      field_ptr= (table->field + (field_ptr - table->getMutableShare()->getFields()));
 
2512
      field_ptr= (table->getFields() + table->getShare()->positionFields(field_ptr));
2511
2513
    }
2512
2514
  }
2513
2515
  else
2514
2516
  {
2515
 
    if (!(field_ptr= table->field))
 
2517
    if (!(field_ptr= table->getFields()))
2516
2518
      return((Field *)0);
2517
2519
    for (; *field_ptr; ++field_ptr)
2518
2520
      if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name, name))
2521
2523
 
2522
2524
  if (field_ptr && *field_ptr)
2523
2525
  {
2524
 
    *cached_field_index_ptr= field_ptr - table->field;
 
2526
    *cached_field_index_ptr= field_ptr - table->getFields();
2525
2527
    field= *field_ptr;
2526
2528
  }
2527
2529
  else
2530
2532
        my_strcasecmp(system_charset_info, name, "_rowid") ||
2531
2533
        table->getShare()->rowid_field_offset == 0)
2532
2534
      return((Field*) 0);
2533
 
    field= table->field[table->getShare()->rowid_field_offset-1];
 
2535
    field= table->getField(table->getShare()->rowid_field_offset-1);
2534
2536
  }
2535
2537
 
2536
2538
  update_field_dependencies(session, field, table);
4162
4164
      For NATURAL joins, used_tables is updated in the IF above.
4163
4165
    */
4164
4166
    if (table)
4165
 
      table->used_fields= table->getShare()->fields;
 
4167
      table->used_fields= table->getShare()->sizeFields();
4166
4168
  }
4167
4169
  if (found)
4168
4170
    return false;
4450
4452
    Table *table=(Table*) hash_element(&open_cache,idx);
4451
4453
    if (not schema_identifier.getPath().compare(table->getMutableShare()->getSchemaName()))
4452
4454
    {
4453
 
      table->getMutableShare()->version= 0L;                    /* Free when thread is ready */
 
4455
      table->getMutableShare()->resetVersion();                 /* Free when thread is ready */
4454
4456
      if (not table->in_use)
4455
4457
        relink_unused(table);
4456
4458
    }
4457
4459
  }
4458
 
  while (unused_tables && !unused_tables->getShare()->version)
 
4460
  while (unused_tables && !unused_tables->getShare()->getVersion())
4459
4461
    hash_delete(&open_cache,(unsigned char*) unused_tables);
4460
4462
}
4461
4463
 
4502
4504
    {
4503
4505
      Session *in_use;
4504
4506
 
4505
 
      table->getMutableShare()->version=0L;             /* Free when thread is ready */
 
4507
      table->getMutableShare()->resetVersion();         /* Free when thread is ready */
4506
4508
      if (!(in_use=table->in_use))
4507
4509
      {
4508
4510
        relink_unused(table);
4540
4542
      else
4541
4543
        result= result || (flags & RTFC_OWNED_BY_Session_FLAG);
4542
4544
    }
4543
 
    while (unused_tables && !unused_tables->getShare()->version)
 
4545
    while (unused_tables && !unused_tables->getShare()->getVersion())
4544
4546
      hash_delete(&open_cache,(unsigned char*) unused_tables);
4545
4547
 
4546
4548
    /* Remove table from table definition cache if it's not in use */