~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Brian Aker
  • Date: 2009-06-09 01:59:10 UTC
  • mfrom: (1054.1.11 merge)
  • Revision ID: brian@gaz-20090609015910-0sfsovp2x8wfbr2c
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
389
389
    ha_rollback(this);
390
390
    xid_cache_delete(&transaction.xid_state);
391
391
  }
392
 
  if (locked_tables)
393
 
  {
394
 
    lock=locked_tables; locked_tables=0;
395
 
    close_thread_tables();
396
 
  }
397
392
  hash_free(&user_vars);
398
393
  close_temporary_tables();
399
394
 
790
785
    my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[transaction.xid_state.xa_state]);
791
786
    return false;
792
787
  }
793
 
  if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN | OPTION_TABLE_LOCK))
 
788
  if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
794
789
  {
795
 
    /* Safety if one did "drop table" on locked tables */
796
 
    if (! locked_tables)
797
 
      options&= ~OPTION_TABLE_LOCK;
798
790
    server_status&= ~SERVER_STATUS_IN_TRANS;
799
791
    if (ha_commit(this))
800
792
      result= false;
808
800
{
809
801
  bool result= true;
810
802
 
811
 
  if (locked_tables)
812
 
  {
813
 
    lock= locked_tables;
814
 
    locked_tables= 0;                   // Will be automatically closed
815
 
    close_thread_tables();                      // Free tables
816
 
  }
817
803
  if (! endActiveTransaction())
818
804
    result= false;
819
805
  else
1818
1804
  */
1819
1805
  assert(open_tables == 0 && temporary_tables == 0 &&
1820
1806
              derived_tables == 0 &&
1821
 
              lock == 0 && locked_tables == 0);
 
1807
              lock == 0);
1822
1808
  set_open_tables_state(backup);
1823
1809
}
1824
1810
 
2019
2005
  for (table= temporary_tables; table; table= tmp_next)
2020
2006
  {
2021
2007
    tmp_next= table->next;
2022
 
    close_temporary(table, 1, 1);
 
2008
    close_temporary(table, true, true);
2023
2009
  }
2024
2010
  temporary_tables= NULL;
2025
2011
}
2225
2211
    transaction.stmt.reset();
2226
2212
  }
2227
2213
 
2228
 
  if (locked_tables)
2229
 
  {
2230
 
 
2231
 
    /* Ensure we are calling ha_reset() for all used tables */
2232
 
    mark_used_tables_as_free_for_reuse(open_tables);
2233
 
 
2234
 
    /*
2235
 
      We are under simple LOCK TABLES so should not do anything else.
2236
 
    */
2237
 
    return;
2238
 
  }
2239
 
 
2240
2214
  if (lock)
2241
2215
  {
2242
2216
    /*
2261
2235
  if (open_tables)
2262
2236
    close_open_tables();
2263
2237
}
 
2238
 
 
2239
 
 
2240
/*
 
2241
  Prepare statement for reopening of tables and recalculation of set of
 
2242
  prelocked tables.
 
2243
 
 
2244
  SYNOPSIS
 
2245
  close_tables_for_reopen()
 
2246
  session    in     Thread context
 
2247
  tables in/out List of tables which we were trying to open and lock
 
2248
 
 
2249
*/
 
2250
 
 
2251
void Session::close_tables_for_reopen(TableList **tables)
 
2252
{
 
2253
  /*
 
2254
    If table list consists only from tables from prelocking set, table list
 
2255
    for new attempt should be empty, so we have to update list's root pointer.
 
2256
  */
 
2257
  if (lex->first_not_own_table() == *tables)
 
2258
    *tables= 0;
 
2259
  lex->chop_off_not_own_tables();
 
2260
  for (TableList *tmp= *tables; tmp; tmp= tmp->next_global)
 
2261
    tmp->table= 0;
 
2262
  close_thread_tables();
 
2263
}
 
2264
 
 
2265
 
 
2266
/*
 
2267
  Open all tables in list, locks them (all, including derived)
 
2268
 
 
2269
  SYNOPSIS
 
2270
  open_and_lock_tables_derived()
 
2271
  session               - thread handler
 
2272
  tables        - list of tables for open&locking
 
2273
  derived     - if to handle derived tables
 
2274
 
 
2275
  RETURN
 
2276
  false - ok
 
2277
  true  - error
 
2278
 
 
2279
  NOTE
 
2280
  The lock will automaticaly be freed by close_thread_tables()
 
2281
 
 
2282
  NOTE
 
2283
  There are two convenience functions:
 
2284
  - simple_open_n_lock_tables(session, tables)  without derived handling
 
2285
  - open_and_lock_tables(session, tables)       with derived handling
 
2286
  Both inline functions call open_and_lock_tables_derived() with
 
2287
  the third argument set appropriately.
 
2288
*/
 
2289
 
 
2290
int Session::open_and_lock_tables(TableList *tables)
 
2291
{
 
2292
  uint32_t counter;
 
2293
  bool need_reopen;
 
2294
 
 
2295
  for ( ; ; )
 
2296
  {
 
2297
    if (open_tables_from_list(&tables, &counter, 0))
 
2298
      return -1;
 
2299
 
 
2300
    if (!lock_tables(this, tables, counter, &need_reopen))
 
2301
      break;
 
2302
    if (!need_reopen)
 
2303
      return -1;
 
2304
    close_tables_for_reopen(&tables);
 
2305
  }
 
2306
  if ((mysql_handle_derived(lex, &mysql_derived_prepare) ||
 
2307
       (fill_derived_tables() &&
 
2308
        mysql_handle_derived(lex, &mysql_derived_filling))))
 
2309
    return 1; /* purecov: inspected */
 
2310
 
 
2311
  return 0;
 
2312
}
 
2313
 
 
2314
 
 
2315
/*
 
2316
  Open all tables in list and process derived tables
 
2317
 
 
2318
  SYNOPSIS
 
2319
  open_normal_and_derived_tables
 
2320
  session               - thread handler
 
2321
  tables        - list of tables for open
 
2322
  flags       - bitmap of flags to modify how the tables will be open:
 
2323
  DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
 
2324
  done a flush or namelock on it.
 
2325
 
 
2326
  RETURN
 
2327
  false - ok
 
2328
  true  - error
 
2329
 
 
2330
  NOTE
 
2331
  This is to be used on prepare stage when you don't read any
 
2332
  data from the tables.
 
2333
*/
 
2334
 
 
2335
bool Session::open_normal_and_derived_tables(TableList *tables, uint32_t flags)
 
2336
{
 
2337
  uint32_t counter;
 
2338
  assert(!(fill_derived_tables()));
 
2339
  if (open_tables_from_list(&tables, &counter, flags) ||
 
2340
      mysql_handle_derived(lex, &mysql_derived_prepare))
 
2341
    return true; /* purecov: inspected */
 
2342
  return false;
 
2343
}