33
#include <drizzled/internal/my_pthread.h>
34
#include <drizzled/internal/thread_var.h>
33
#include "drizzled/internal/my_pthread.h"
34
#include "drizzled/internal/thread_var.h"
36
36
#include <drizzled/sql_select.h>
37
37
#include <drizzled/error.h>
44
44
#include <drizzled/check_stack_overrun.h>
45
45
#include <drizzled/lock.h>
46
46
#include <drizzled/plugin/listen.h>
47
#include <drizzled/cached_directory.h>
48
#include <drizzled/field/epoch.h>
47
#include "drizzled/cached_directory.h"
48
#include <drizzled/field/timestamp.h>
49
49
#include <drizzled/field/null.h>
50
#include <drizzled/sql_table.h>
51
#include <drizzled/global_charset_info.h>
52
#include <drizzled/pthread_globals.h>
53
#include <drizzled/internal/iocache.h>
54
#include <drizzled/drizzled.h>
55
#include <drizzled/plugin/authorization.h>
56
#include <drizzled/table/temporary.h>
57
#include <drizzled/table/placeholder.h>
58
#include <drizzled/table/unused.h>
59
#include <drizzled/plugin/storage_engine.h>
60
#include <drizzled/session.h>
62
#include <drizzled/refresh_version.h>
50
#include "drizzled/sql_table.h"
51
#include "drizzled/global_charset_info.h"
52
#include "drizzled/pthread_globals.h"
53
#include "drizzled/internal/iocache.h"
54
#include "drizzled/drizzled.h"
55
#include "drizzled/plugin/authorization.h"
56
#include "drizzled/table/temporary.h"
57
#include "drizzled/table/placeholder.h"
58
#include "drizzled/table/unused.h"
64
60
using namespace std;
114
110
This has to be done to ensure that the table share is removed from
115
111
the table defintion cache as soon as the last instance is removed
117
identifier::Table identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), message::Table::INTERNAL);
118
const identifier::Table::Key &key(identifier.getKey());
113
TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), message::Table::INTERNAL);
114
const TableIdentifier::Key &key(identifier.getKey());
119
115
TableShare *share= new TableShare(identifier.getType(),
121
117
const_cast<char *>(key.vector()), static_cast<uint32_t>(table->getShare()->getCacheKeySize()));
123
119
table->cursor->close();
124
120
table->db_stat= 0; // Mark cursor closed
125
table::instance::release(table->getMutableShare());
121
TableShare::release(table->getMutableShare());
126
122
table->setShare(share);
236
233
bool found= false;
237
234
for (TableList *table= tables; table; table= table->next_local)
239
identifier::Table identifier(table->getSchemaName(), table->getTableName());
236
TableIdentifier identifier(table->getSchemaName(), table->getTableName());
240
237
if (table::Cache::singleton().removeTable(session, identifier,
241
238
RTFC_OWNED_BY_Session_FLAG))
290
287
(table->open_placeholder && wait_for_placeholders)))
293
COND_refresh.wait(scopedLock);
290
boost_unique_lock_t scoped(table::Cache::singleton().mutex(), boost::adopt_lock_t());
291
COND_refresh.wait(scoped);
300
299
old locks. This should always succeed (unless some external process
301
300
has removed the tables)
303
result= session->reopen_tables();
302
result= session->reopen_tables(true, true);
305
304
/* Set version for table */
306
305
for (Table *table= session->open_tables; table ; table= table->getNext())
331
332
move one table to free list
334
bool Session::free_cached_table(boost::mutex::scoped_lock &scopedLock)
335
bool Session::free_cached_table()
336
337
bool found_old_table= false;
340
338
table::Concurrent *table= static_cast<table::Concurrent *>(open_tables);
342
340
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
425
423
for (; table; table= table->*link )
427
if ((table->table == 0 || table->table->getShare()->getType() == message::Table::STANDARD) and
428
my_strcasecmp(system_charset_info, table->getSchemaName(), db_name) == 0 and
429
my_strcasecmp(system_charset_info, table->getTableName(), table_name) == 0)
425
if ((table->table == 0 || table->table->getShare()->getType() == message::Table::STANDARD) &&
426
strcasecmp(table->getSchemaName(), db_name) == 0 &&
427
strcasecmp(table->getTableName(), table_name) == 0)
524
void Open_tables_state::doGetTableNames(const identifier::Schema &schema_identifier,
520
void Open_tables_state::doGetTableNames(const SchemaIdentifier &schema_identifier,
525
521
std::set<std::string>& set_of_names)
527
523
for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
536
532
void Open_tables_state::doGetTableNames(CachedDirectory &,
537
const identifier::Schema &schema_identifier,
533
const SchemaIdentifier &schema_identifier,
538
534
std::set<std::string> &set_of_names)
540
536
doGetTableNames(schema_identifier, set_of_names);
543
void Open_tables_state::doGetTableIdentifiers(const identifier::Schema &schema_identifier,
544
identifier::Table::vector &set_of_identifiers)
539
void Open_tables_state::doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
540
TableIdentifier::vector &set_of_identifiers)
546
542
for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
548
544
if (schema_identifier.compare(table->getShare()->getSchemaName()))
550
set_of_identifiers.push_back(identifier::Table(table->getShare()->getSchemaName(),
546
set_of_identifiers.push_back(TableIdentifier(table->getShare()->getSchemaName(),
551
547
table->getShare()->getTableName(),
552
548
table->getShare()->getPath()));
557
553
void Open_tables_state::doGetTableIdentifiers(CachedDirectory &,
558
const identifier::Schema &schema_identifier,
559
identifier::Table::vector &set_of_identifiers)
554
const SchemaIdentifier &schema_identifier,
555
TableIdentifier::vector &set_of_identifiers)
561
557
doGetTableIdentifiers(schema_identifier, set_of_identifiers);
564
bool Open_tables_state::doDoesTableExist(const identifier::Table &identifier)
560
bool Open_tables_state::doDoesTableExist(const TableIdentifier &identifier)
566
562
for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
580
int Open_tables_state::doGetTableDefinition(const identifier::Table &identifier,
581
message::Table &table_proto)
576
int Open_tables_state::doGetTableDefinition(const TableIdentifier &identifier,
577
message::Table &table_proto)
583
579
for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
667
663
void Session::unlink_open_table(Table *find)
669
const identifier::Table::Key find_key(find->getShare()->getCacheKey());
665
const TableIdentifier::Key find_key(find->getShare()->getCacheKey());
671
667
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
674
670
Note that we need to hold table::Cache::singleton().mutex() while changing the
675
671
open_tables list. Another thread may work on it.
676
(See: table::Cache::singleton().removeTable(), wait_completed_table())
672
(See: table::Cache::singleton().removeTable(), mysql_wait_completed_table())
677
673
Closing a MERGE child before the parent would be fatal if the
678
674
other thread tries to abort the MERGE lock in between.
720
716
table that was locked with LOCK TABLES.
723
void Session::drop_open_table(Table *table, const identifier::Table &identifier)
719
void Session::drop_open_table(Table *table, const TableIdentifier &identifier)
725
721
if (table->getShare()->getType())
734
730
that something has happened.
736
732
unlink_open_table(table);
737
(void)plugin::StorageEngine::dropTable(*this, identifier);
733
plugin::StorageEngine::dropTable(*this, identifier);
798
table::Placeholder *Session::table_cache_insert_placeholder(const drizzled::identifier::Table &arg)
794
table::Placeholder *Session::table_cache_insert_placeholder(const drizzled::TableIdentifier &arg)
800
796
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
803
799
Create a table entry with the right key and with an old refresh version
805
identifier::Table identifier(arg.getSchemaName(), arg.getTableName(), message::Table::INTERNAL);
801
TableIdentifier identifier(arg.getSchemaName(), arg.getTableName(), message::Table::INTERNAL);
806
802
table::Placeholder *table= new table::Placeholder(this, identifier);
808
804
if (not table::Cache::singleton().insert(table))
837
833
@retval true Error occured (OOM)
838
834
@retval false Success. 'table' parameter set according to above rules.
840
bool Session::lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table)
836
bool Session::lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table)
842
const identifier::Table::Key &key(identifier.getKey());
838
const TableIdentifier::Key &key(identifier.getKey());
844
840
boost_unique_lock_t scope_lock(table::Cache::singleton().mutex()); /* Obtain a name lock even though table is not in cache (like for create table) */
919
identifier::Table identifier(table_list->getSchemaName(), table_list->getTableName());
920
const identifier::Table::Key &key(identifier.getKey());
915
TableIdentifier identifier(table_list->getSchemaName(), table_list->getTableName());
916
const TableIdentifier::Key &key(identifier.getKey());
921
917
table::CacheRange ppp;
954
950
if (flags & DRIZZLE_OPEN_TEMPORARY_ONLY)
956
my_error(ER_TABLE_UNKNOWN, identifier);
952
my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->getSchemaName(), table_list->getTableName());
1056
1052
/* Avoid self-deadlocks by detecting self-dependencies. */
1057
1053
if (table->open_placeholder && table->in_use == this)
1055
table::Cache::singleton().mutex().unlock();
1059
1056
my_error(ER_UPDATE_TABLE_USED, MYF(0), table->getShare()->getTableName());
1091
1088
/* wait_for_conditionwill unlock table::Cache::singleton().mutex() for us */
1092
1089
wait_for_condition(table::Cache::singleton().mutex(), COND_refresh);
1093
scopedLock.release();
1097
scopedLock.unlock();
1093
table::Cache::singleton().mutex().unlock();
1101
1096
There is a refresh in progress for this table.
1102
1097
Signal the caller that it has to try again.
1105
1100
*refresh= true;
1113
1106
table::getUnused().unlink(static_cast<table::Concurrent *>(table));
1123
1116
if (table_list->isCreate())
1125
identifier::Table lock_table_identifier(table_list->getSchemaName(), table_list->getTableName(), message::Table::STANDARD);
1118
TableIdentifier lock_table_identifier(table_list->getSchemaName(), table_list->getTableName(), message::Table::STANDARD);
1127
1120
if (not plugin::StorageEngine::doesTableExist(*this, lock_table_identifier))
1224
1222
the strings are used in a loop even after the share may be freed.
1227
void Session::close_data_files_and_morph_locks(const identifier::Table &identifier)
1225
void Session::close_data_files_and_morph_locks(const TableIdentifier &identifier)
1229
1227
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle()); /* Adjust locks at the end of ALTER TABLEL */
1274
1272
@return false in case of success, true - otherwise.
1277
bool Session::reopen_tables()
1275
bool Session::reopen_tables(bool get_locks, bool)
1279
1277
Table *table,*next,**prev;
1280
Table **tables= 0; // For locks
1281
Table **tables_ptr= 0; // For locks
1278
Table **tables,**tables_ptr; // For locks
1279
bool error=0, not_used;
1283
1280
const uint32_t flags= DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN |
1284
1281
DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK |
1285
1282
DRIZZLE_LOCK_IGNORE_FLUSH;
1326
1326
some_tables_deleted= false;
1328
if ((local_lock= lockTables(tables, (uint32_t) (tables_ptr - tables), flags)))
1328
if ((local_lock= lockTables(tables, (uint32_t) (tables_ptr - tables),
1440
/* Wait until all used tables are refreshed */
1442
bool wait_for_tables(Session *session)
1446
session->set_proc_info("Waiting for tables");
1448
boost_unique_lock_t lock(table::Cache::singleton().mutex());
1449
while (not session->getKilled())
1451
session->some_tables_deleted= false;
1452
session->close_old_data_files(false, dropping_tables != 0);
1453
if (not table::Cache::singleton().areTablesUsed(session->open_tables, 1))
1457
COND_refresh.wait(lock);
1459
if (session->getKilled())
1460
result= true; // aborted
1463
/* Now we can open all tables without any interference */
1464
session->set_proc_info("Reopen tables");
1465
session->version= refresh_version;
1466
result= session->reopen_tables(false, false);
1469
session->set_proc_info(0);
1439
1476
drop tables from locked list
1462
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier)
1499
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier)
1464
1501
Table *table,*next,**prev, *found= 0;
1465
1502
prev= &session->open_tables;
1468
1505
Note that we need to hold table::Cache::singleton().mutex() while changing the
1469
1506
open_tables list. Another thread may work on it.
1470
(See: table::Cache::singleton().removeTable(), wait_completed_table())
1507
(See: table::Cache::singleton().removeTable(), mysql_wait_completed_table())
1471
1508
Closing a MERGE child before the parent would be fatal if the
1472
1509
other thread tries to abort the MERGE lock in between.
1515
1551
other threads trying to get the lock.
1518
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier)
1554
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier)
1521
1557
for (table= session->open_tables; table ; table= table->getNext())
1597
1632
* to see if it exists so that an unauthorized user cannot phish for
1598
1633
* table/schema information via error messages
1600
identifier::Table the_table(tables->getSchemaName(), tables->getTableName());
1601
if (not plugin::Authorization::isAuthorized(*user(), the_table))
1635
TableIdentifier the_table(tables->getSchemaName(), tables->getTableName());
1636
if (not plugin::Authorization::isAuthorized(getSecurityContext(),
1603
1639
result= -1; // Fatal error
1705
1743
assert(lock == 0); // You must lock everything at once
1706
1744
if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK)
1708
if (not (lock= lockTables(&table_list->table, 1, 0)))
1745
if (! (lock= lockTables(&table_list->table, 1, 0, &refresh)))
1713
1749
set_proc_info(0);
1761
1797
Table **start,**ptr;
1762
1798
uint32_t lock_flag= DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN;
1764
if (!(ptr=start=(Table**) session->getMemRoot()->allocate(sizeof(Table*)*count)))
1800
if (!(ptr=start=(Table**) session->alloc(sizeof(Table*)*count)))
1767
1802
for (table= tables; table; table= table->next_global)
1769
1804
if (!table->placeholder())
1770
1805
*(ptr++)= table->table;
1773
if (not (session->lock= session->lockTables(start, (uint32_t) (ptr - start), lock_flag)))
1808
if (!(session->lock= session->lockTables(start, (uint32_t) (ptr - start), lock_flag, need_reopen)))
1808
1843
table::Temporary *new_tmp_table= new table::Temporary(identifier.getType(),
1810
const_cast<char *>(const_cast<identifier::Table&>(identifier).getPath().c_str()),
1845
const_cast<char *>(const_cast<TableIdentifier&>(identifier).getPath().c_str()),
1811
1846
static_cast<uint32_t>(identifier.getPath().length()));
1812
1847
if (not new_tmp_table)
1929
1964
const char *name, uint32_t , Item **,
1930
1965
bool, TableList **actual_table)
1932
List<Natural_join_column>::iterator
1933
field_it(table_ref->join_columns->begin());
1967
List_iterator_fast<Natural_join_column>
1968
field_it(*(table_ref->join_columns));
1934
1969
Natural_join_column *nj_col, *curr_nj_col;
1935
1970
Field *found_field;
1947
my_error(ER_NON_UNIQ_ERROR, MYF(0), name, session->where());
1982
my_error(ER_NON_UNIQ_ERROR, MYF(0), name, session->where);
1950
1985
nj_col= curr_nj_col;
2298
Select_Lex *current_sel= session->getLex()->current_select;
2333
Select_Lex *current_sel= session->lex->current_select;
2299
2334
Select_Lex *last_select= table_ref->select_lex;
2301
2336
If the field was an outer referencee, mark all selects using this
2354
2389
if (report_error == REPORT_ALL_ERRORS ||
2355
2390
report_error == IGNORE_EXCEPT_NON_UNIQUE)
2356
2391
my_error(ER_NON_UNIQ_ERROR, MYF(0),
2357
table_name ? item->full_name() : name, session->where());
2392
table_name ? item->full_name() : name, session->where);
2358
2393
return (Field*) 0;
2360
2395
found= cur_field;
2387
2422
strcat(buff, table_name);
2388
2423
table_name=buff;
2390
my_error(ER_UNKNOWN_TABLE, MYF(0), table_name, session->where());
2425
my_error(ER_UNKNOWN_TABLE, MYF(0), table_name, session->where);
2394
2429
if (report_error == REPORT_ALL_ERRORS ||
2395
2430
report_error == REPORT_EXCEPT_NON_UNIQUE)
2396
my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(), session->where());
2431
my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(), session->where);
2398
2433
found= not_found_field;
2444
2479
find_item_error_report_type report_error,
2445
2480
enum_resolution_type *resolution)
2447
List<Item>::iterator li(items.begin());
2482
List_iterator<Item> li(items);
2448
2483
Item **found=0, **found_unaliased= 0, *item;
2449
2484
const char *db_name=0;
2450
2485
const char *field_name=0;
2521
2556
if (report_error != IGNORE_ERRORS)
2522
2557
my_error(ER_NON_UNIQ_ERROR, MYF(0),
2523
find->full_name(), session->where());
2558
find->full_name(), session->where);
2524
2559
return (Item**) 0;
2526
2561
found_unaliased= li.ref();
2551
2586
continue; // Same field twice
2552
2587
if (report_error != IGNORE_ERRORS)
2553
2588
my_error(ER_NON_UNIQ_ERROR, MYF(0),
2554
find->full_name(), session->where());
2589
find->full_name(), session->where);
2555
2590
return (Item**) 0;
2557
2592
found= li.ref();
2604
2639
if (report_error != IGNORE_ERRORS)
2605
2640
my_error(ER_NON_UNIQ_ERROR, MYF(0),
2606
find->full_name(), session->where());
2641
find->full_name(), session->where);
2607
2642
return (Item **) 0;
2609
2644
if (found_unaliased)
2620
2655
if (report_error == REPORT_ALL_ERRORS)
2621
2656
my_error(ER_BAD_FIELD_ERROR, MYF(0),
2622
find->full_name(), session->where());
2657
find->full_name(), session->where);
2623
2658
return (Item **) 0;
2648
2683
test_if_string_in_list(const char *find, List<String> *str_list)
2650
List<String>::iterator str_list_it(str_list->begin());
2685
List_iterator<String> str_list_it(*str_list);
2651
2686
String *curr_str;
2652
2687
size_t find_length= strlen(find);
2653
2688
while ((curr_str= str_list_it++))
2790
2825
if (cur_nj_col_2->is_common ||
2791
2826
(found && (!using_fields || is_using_column_1)))
2793
my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1, session->where());
2828
my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1, session->where);
2794
2829
return(result);
2796
2831
nj_col_2= cur_nj_col_2;
2981
3016
if (using_fields && found_using_fields < using_fields->elements)
2983
3018
String *using_field_name;
2984
List<String>::iterator using_fields_it(using_fields->begin());
3019
List_iterator_fast<String> using_fields_it(*using_fields);
2985
3020
while ((using_field_name= using_fields_it++))
2987
3022
const char *using_field_name_ptr= using_field_name->c_ptr();
2988
List<Natural_join_column>::iterator
2989
it(natural_using_join->join_columns->begin());
3023
List_iterator_fast<Natural_join_column>
3024
it(*(natural_using_join->join_columns));
2990
3025
Natural_join_column *common_field;
2995
3030
if (!(common_field= it++))
2997
3032
my_error(ER_BAD_FIELD_ERROR, MYF(0), using_field_name_ptr,
2999
3034
return(result);
3001
3036
if (!my_strcasecmp(system_charset_info,
3068
3103
/* Call the procedure recursively for each nested table reference. */
3069
3104
if (table_ref->getNestedJoin())
3071
List<TableList>::iterator nested_it(table_ref->getNestedJoin()->join_list.begin());
3106
List_iterator_fast<TableList> nested_it(table_ref->getNestedJoin()->join_list);
3072
3107
TableList *same_level_left_neighbor= nested_it++;
3073
3108
TableList *same_level_right_neighbor= NULL;
3074
3109
/* Left/right-most neighbors, possibly at higher levels in the join tree. */
3123
3158
assert(table_ref->getNestedJoin() &&
3124
3159
table_ref->getNestedJoin()->join_list.elements == 2);
3125
List<TableList>::iterator operand_it(table_ref->getNestedJoin()->join_list.begin());
3160
List_iterator_fast<TableList> operand_it(table_ref->getNestedJoin()->join_list);
3127
3162
Notice that the order of join operands depends on whether table_ref
3128
3163
represents a LEFT or a RIGHT join. In a RIGHT join, the operands are
3218
3253
List<TableList> *from_clause,
3219
3254
Name_resolution_context *context)
3221
session->setWhere("from clause");
3256
session->where= "from clause";
3222
3257
if (from_clause->elements == 0)
3223
3258
return false; /* We come here in the case of UNIONs. */
3225
List<TableList>::iterator table_ref_it(from_clause->begin());
3260
List_iterator_fast<TableList> table_ref_it(*from_clause);
3226
3261
TableList *table_ref; /* Current table reference. */
3227
3262
/* Table reference to the left of the current. */
3228
3263
TableList *left_neighbor;
3275
List<Item>::iterator it(fields.begin());
3310
List_iterator<Item> it(fields);
3277
session->getLex()->current_select->cur_pos_in_select_list= 0;
3312
session->lex->current_select->cur_pos_in_select_list= 0;
3278
3313
while (wild_num && (item= it++))
3280
3315
if (item->type() == Item::FIELD_ITEM &&
3285
3320
uint32_t elem= fields.elements;
3286
3321
bool any_privileges= ((Item_field *) item)->any_privileges;
3287
Item_subselect *subsel= session->getLex()->current_select->master_unit()->item;
3322
Item_subselect *subsel= session->lex->current_select->master_unit()->item;
3289
3324
subsel->substype() == Item_subselect::EXISTS_SUBS)
3318
session->getLex()->current_select->cur_pos_in_select_list++;
3353
session->lex->current_select->cur_pos_in_select_list++;
3320
session->getLex()->current_select->cur_pos_in_select_list= UNDEF_POS;
3355
session->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
3333
3368
register Item *item;
3334
3369
enum_mark_columns save_mark_used_columns= session->mark_used_columns;
3335
nesting_map save_allow_sum_func= session->getLex()->allow_sum_func;
3336
List<Item>::iterator it(fields.begin());
3370
nesting_map save_allow_sum_func= session->lex->allow_sum_func;
3371
List_iterator<Item> it(fields);
3337
3372
bool save_is_item_list_lookup;
3339
3374
session->mark_used_columns= mark_used_columns;
3340
3375
if (allow_sum_func)
3341
session->getLex()->allow_sum_func|= 1 << session->getLex()->current_select->nest_level;
3342
session->setWhere(Session::DEFAULT_WHERE);
3343
save_is_item_list_lookup= session->getLex()->current_select->is_item_list_lookup;
3344
session->getLex()->current_select->is_item_list_lookup= 0;
3376
session->lex->allow_sum_func|= 1 << session->lex->current_select->nest_level;
3377
session->where= Session::DEFAULT_WHERE;
3378
save_is_item_list_lookup= session->lex->current_select->is_item_list_lookup;
3379
session->lex->current_select->is_item_list_lookup= 0;
3347
3382
To prevent fail on forward lookup we fill it with zerows,
3351
3386
There is other way to solve problem: fill array with pointers to list,
3352
3387
but it will be slower.
3354
TODO-> remove it when (if) we made one list for allfields and ref_pointer_array
3389
TODO: remove it when (if) we made one list for allfields and
3356
3392
if (ref_pointer_array)
3358
3393
memset(ref_pointer_array, 0, sizeof(Item *) * fields.elements);
3361
3395
Item **ref= ref_pointer_array;
3362
session->getLex()->current_select->cur_pos_in_select_list= 0;
3396
session->lex->current_select->cur_pos_in_select_list= 0;
3363
3397
while ((item= it++))
3365
3399
if ((!item->fixed && item->fix_fields(session, it.ref())) || (item= *(it.ref()))->check_cols(1))
3367
session->getLex()->current_select->is_item_list_lookup= save_is_item_list_lookup;
3368
session->getLex()->allow_sum_func= save_allow_sum_func;
3401
session->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
3402
session->lex->allow_sum_func= save_allow_sum_func;
3369
3403
session->mark_used_columns= save_mark_used_columns;
3376
3410
item->split_sum_func(session, ref_pointer_array, *sum_func_list);
3377
3411
session->used_tables|= item->used_tables();
3378
session->getLex()->current_select->cur_pos_in_select_list++;
3412
session->lex->current_select->cur_pos_in_select_list++;
3380
session->getLex()->current_select->is_item_list_lookup= save_is_item_list_lookup;
3381
session->getLex()->current_select->cur_pos_in_select_list= UNDEF_POS;
3414
session->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
3415
session->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
3383
session->getLex()->allow_sum_func= save_allow_sum_func;
3417
session->lex->allow_sum_func= save_allow_sum_func;
3384
3418
session->mark_used_columns= save_mark_used_columns;
3385
3419
return(test(session->is_error()));
3551
3585
insert_fields(Session *session, Name_resolution_context *context, const char *db_name,
3552
const char *table_name, List<Item>::iterator *it,
3586
const char *table_name, List_iterator<Item> *it,
3555
3589
Field_iterator_table_ref field_iterator;
3588
3622
assert(tables->is_leaf_for_name_resolution());
3590
3624
if ((table_name && my_strcasecmp(table_alias_charset, table_name, tables->alias)) ||
3591
(db_name && my_strcasecmp(system_charset_info, tables->getSchemaName(),db_name)))
3625
(db_name && strcasecmp(tables->getSchemaName(),db_name)))
3656
3689
session->used_tables|= item->used_tables();
3659
session->getLex()->current_select->cur_pos_in_select_list++;
3690
session->lex->current_select->cur_pos_in_select_list++;
3662
3693
In case of stored tables, all fields are considered as used,
3675
3706
qualified '*', and all columns were coalesced, we have to give a more
3676
3707
meaningful message than ER_BAD_TABLE_ERROR.
3680
3710
my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
3684
3712
my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name);
3709
3736
int Session::setup_conds(TableList *leaves, COND **conds)
3711
3738
Session *session= this;
3712
Select_Lex *select_lex= session->getLex()->current_select;
3739
Select_Lex *select_lex= session->lex->current_select;
3713
3740
TableList *table= NULL; // For HP compilers
3714
3741
void *save_session_marker= session->session_marker;
3731
3758
session->session_marker= (void*)1;
3734
session->setWhere("where clause");
3761
session->where="where clause";
3735
3762
if ((!(*conds)->fixed && (*conds)->fix_fields(session, conds)) ||
3736
3763
(*conds)->check_cols(1))
3737
3764
goto err_no_arena;
3754
3781
/* Make a join an a expression */
3755
3782
session->session_marker= (void*)embedded;
3756
session->setWhere("on clause");
3783
session->where="on clause";
3757
3784
if ((!embedded->on_expr->fixed && embedded->on_expr->fix_fields(session, &embedded->on_expr)) ||
3758
3785
embedded->on_expr->check_cols(1))
3759
3786
goto err_no_arena;
3768
3795
session->session_marker= save_session_marker;
3770
session->getLex()->current_select->is_item_list_lookup= save_is_item_list_lookup;
3797
session->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
3771
3798
return(test(session->is_error()));
3806
3833
fill_record(Session *session, List<Item> &fields, List<Item> &values, bool ignore_errors)
3808
List<Item>::iterator f(fields.begin());
3809
List<Item>::iterator v(values.begin());
3835
List_iterator_fast<Item> f(fields),v(values);
3811
3837
Item_field *field;
3872
3898
bool fill_record(Session *session, Field **ptr, List<Item> &values, bool)
3874
List<Item>::iterator v(values.begin());
3900
List_iterator_fast<Item> v(values);
3876
3902
Table *table= 0;
3889
3915
table= (*ptr)->getTable();
3890
3916
table->auto_increment_field_not_null= false;
3893
3918
while ((field = *ptr++) && ! session->is_error())
3896
3921
table= field->getTable();
3898
3922
if (field == table->next_number_field)
3899
3923
table->auto_increment_field_not_null= true;
3901
3924
if (value->save_in_field(field, 0) < 0)
3914
3937
bool drizzle_rm_tmp_tables()
3917
3941
assert(drizzle_tmpdir.size());
3918
Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
3943
if (!(session= new Session(plugin::Listen::getNullClient())))
3922
session->thread_stack= (char*) session.get();
3945
session->thread_stack= (char*) &session;
3923
3946
session->storeGlobals();
3925
3948
plugin::StorageEngine::removeLostTemporaryTables(*session, drizzle_tmpdir.c_str());