23 #if TIME_WITH_SYS_TIME
24 # include <sys/time.h>
28 # include <sys/time.h>
33 #include <drizzled/internal/my_pthread.h>
34 #include <drizzled/internal/thread_var.h>
36 #include <drizzled/sql_select.h>
37 #include <drizzled/error.h>
38 #include <drizzled/gettext.h>
39 #include <drizzled/nested_join.h>
40 #include <drizzled/sql_base.h>
42 #include <drizzled/item/cmpfunc.h>
43 #include <drizzled/replication_services.h>
44 #include <drizzled/check_stack_overrun.h>
45 #include <drizzled/lock.h>
46 #include <drizzled/plugin/listen.h>
48 #include <drizzled/field/epoch.h>
49 #include <drizzled/field/null.h>
51 #include <drizzled/charset.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>
61 #include <drizzled/item/subselect.h>
62 #include <drizzled/sql_lex.h>
63 #include <drizzled/catalog/local.h>
64 #include <drizzled/open_tables_state.h>
65 #include <drizzled/table/cache.h>
71 extern bool volatile shutdown_in_progress;
73 void table_cache_free()
77 table::getUnused().clear();
78 table::getCache().clear();
99 void close_handle_and_leave_table_as_lock(Table *table)
101 assert(table->db_stat);
102 assert(table->getShare()->getType() == message::Table::STANDARD);
109 identifier::Table identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), message::Table::INTERNAL);
110 TableShare *share=
new TableShare(identifier.getType(), identifier, identifier.getKey().vector(),
static_cast<uint32_t
>(table->getShare()->getCacheKeySize()));
112 table->cursor->close();
114 table::instance::release(table->getMutableShare());
115 table->setShare(share);
124 void Table::intern_close_table()
135 void Table::free_io_cache()
139 sort.io_cache->close_cached_file();
140 safe_delete(sort.io_cache);
160 bool Session::close_cached_tables(TableList *tables,
bool wait_for_refresh,
bool wait_for_placeholders)
163 Session *session=
this;
166 boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
170 table::getUnused().clear();
175 for (TableList *table= tables; table; table= table->next_local)
177 if (table::Cache::removeTable(*session, identifier::Table(table->getSchemaName(), table->getTableName()), RTFC_OWNED_BY_Session_FLAG))
183 wait_for_refresh=
false;
186 if (wait_for_refresh)
192 session->mysys_var->current_mutex= &table::Cache::mutex();
193 session->mysys_var->current_cond= &COND_refresh;
194 session->set_proc_info(
"Flushing tables");
196 session->close_old_data_files();
200 while (found && ! session->getKilled())
203 for (table::CacheMap::const_iterator iter= table::getCache().begin();
204 iter != table::getCache().end();
207 Table *table= iter->second;
209 if (table->in_use == session)
225 if (table->needs_reopen_or_name_lock() && (table->db_stat ||
226 (table->open_placeholder && wait_for_placeholders)))
229 COND_refresh.wait(scopedLock);
239 result= session->reopen_tables();
242 for (Table *table= session->open_tables.open_tables_; table ; table= table->getNext())
248 if (table->reginfo.lock_type < TL_WRITE_ALLOW_WRITE)
249 table->getMutableShare()->refreshVersion();
254 if (wait_for_refresh)
256 boost::mutex::scoped_lock scopedLock(session->mysys_var->mutex);
257 session->mysys_var->current_mutex= 0;
258 session->mysys_var->current_cond= 0;
259 session->set_proc_info(0);
270 bool Open_tables_state::free_cached_table()
274 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
275 assert(table->key_read == 0);
276 assert(not table->
cursor || table->
cursor->inited == Cursor::NONE);
278 open_tables_= table->getNext();
280 if (table->needs_reopen_or_name_lock() ||
281 version != g_refresh_version || !table->
db_stat)
283 table::remove_table(table);
290 assert(not table->open_placeholder);
296 table::getUnused().link(table);
309 void Open_tables_state::close_open_tables()
311 bool found_old_table=
false;
313 safe_mutex_assert_not_owner(table::Cache::mutex().native_handle());
315 boost::mutex::scoped_lock scoped_lock(table::Cache::mutex());
319 found_old_table|= free_cached_table();
349 const char *table_name)
351 for (; table; table= table->*link)
353 if ((table->
table == 0 || table->
table->getShare()->getType() == message::Table::STANDARD)
354 && not system_charset_info->strcasecmp(table->getSchemaName(), db_name)
355 && not system_charset_info->strcasecmp(table->getTableName(), table_name))
400 TableList* unique_table(TableList *table, TableList *table_list,
404 const char *d_name, *t_name, *t_alias;
419 if (table->table && table->table->getShare()->getType() != message::Table::STANDARD)
428 d_name= table->getSchemaName();
429 t_name= table->getTableName();
430 t_alias= table->alias;
434 if ((! (res= find_table_in_global_list(table_list, d_name, t_name))) ||
435 ((!res->table || res->table != table->table) &&
436 (!check_alias || !(files_charset_info->strcasecmp(t_alias, res->alias))) &&
437 res->select_lex && !res->select_lex->exclude_from_table_unique_test))
444 table_list= res->next_global;
450 void Open_tables_state::doGetTableNames(
const identifier::Schema &schema_identifier,
451 std::set<std::string>& set_of_names)
453 for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
455 if (schema_identifier.compare(table->getShare()->getSchemaName()))
457 set_of_names.insert(table->getShare()->getTableName());
462 void Open_tables_state::doGetTableNames(CachedDirectory &,
463 const identifier::Schema &schema_identifier,
464 std::set<std::string> &set_of_names)
466 doGetTableNames(schema_identifier, set_of_names);
469 void Open_tables_state::doGetTableIdentifiers(
const identifier::Schema &schema_identifier,
470 identifier::table::vector &set_of_identifiers)
472 for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
474 if (schema_identifier.compare(table->getShare()->getSchemaName()))
476 set_of_identifiers.push_back(identifier::Table(table->getShare()->getSchemaName(),
477 table->getShare()->getTableName(),
478 table->getShare()->getPath()));
483 void Open_tables_state::doGetTableIdentifiers(CachedDirectory &,
484 const identifier::Schema &schema_identifier,
485 identifier::table::vector &set_of_identifiers)
487 doGetTableIdentifiers(schema_identifier, set_of_identifiers);
490 bool Open_tables_state::doDoesTableExist(
const identifier::Table &identifier)
492 for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
494 if (table->getShare()->getType() == message::Table::TEMPORARY)
496 if (identifier.getKey() == table->getShare()->getCacheKey())
506 int Open_tables_state::doGetTableDefinition(
const identifier::Table &identifier,
507 message::Table &table_proto)
509 for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
511 if (table->getShare()->getType() == message::Table::TEMPORARY)
513 if (identifier.getKey() == table->getShare()->getCacheKey())
515 table_proto.CopyFrom(*(table->getShare()->getTableMessage()));
525 Table *Open_tables_state::find_temporary_table(
const identifier::Table &identifier)
527 for (Table *table= temporary_tables ; table ; table= table->getNext())
529 if (identifier.getKey() == table->getShare()->getCacheKey())
565 Table* table= find_temporary_table(identifier);
570 if (table->query_id && table->query_id != session_.getQueryId())
572 my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
575 close_temporary_table(table);
590 void Session::unlink_open_table(
Table *find)
594 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
603 for (prev= &open_tables.open_tables_; *prev; )
607 if (list->getShare()->getCacheKey() == find_key)
610 *prev= list->getNext();
613 table::remove_table(static_cast<table::Concurrent *>(list));
618 prev= list->getNextPtr();
648 if (table->getShare()->getType())
650 open_tables.close_temporary_table(table);
654 boost::mutex::scoped_lock scoped_lock(table::Cache::mutex());
659 unlink_open_table(table);
660 (void)plugin::StorageEngine::dropTable(*
this, identifier);
676 void Session::wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond)
679 const char *saved_proc_info;
680 mysys_var->current_mutex= &mutex;
681 mysys_var->current_cond= &cond;
682 saved_proc_info= get_proc_info();
683 set_proc_info(
"Waiting for table");
695 boost::mutex::scoped_lock scopedLock(mutex, boost::adopt_lock_t());
698 cond.wait(scopedLock);
701 boost::mutex::scoped_lock mysys_scopedLock(mysys_var->mutex);
702 mysys_var->current_mutex= 0;
703 mysys_var->current_cond= 0;
704 set_proc_info(saved_proc_info);
723 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
728 identifier::Table identifier(arg.getSchemaName(), arg.getTableName(), message::Table::INTERNAL);
730 table::Cache::insert(table);
759 boost::mutex::scoped_lock scope_lock(table::Cache::mutex());
760 if (find_ptr(table::getCache(), key))
762 Table& table= table_cache_insert_placeholder(identifier);
763 table.open_placeholder=
true;
764 table.setNext(open_tables.open_tables_);
765 open_tables.open_tables_= &table;
802 Table *Session::openTable(
TableList *table_list,
bool *refresh, uint32_t flags)
805 const char *alias= table_list->alias;
808 assert(lex().is_lex_started);
817 if (check_stack_overrun(
this, STACK_MIN_SIZE_FOR_OPEN, (
unsigned char *)&alias))
827 identifier::Table identifier(table_list->getSchemaName(), table_list->getTableName());
828 const identifier::Table::Key &key(identifier.getKey());
829 table::CacheRange ppp;
839 for (table= open_tables.getTemporaryTables(); table ; table=table->getNext())
841 if (table->getShare()->getCacheKey() == key)
851 my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
854 table->query_id= getQueryId();
862 if (flags & DRIZZLE_OPEN_TEMPORARY_ONLY)
864 my_error(ER_TABLE_UNKNOWN, identifier);
877 if (!open_tables.open_tables_)
879 open_tables.version= g_refresh_version;
881 else if ((open_tables.version != g_refresh_version) &&
882 ! (flags & DRIZZLE_LOCK_IGNORE_FLUSH))
907 boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
919 ppp= table::getCache().equal_range(key);
922 for (table::CacheMap::const_iterator iter= ppp.first; iter != ppp.second; ++iter, table= NULL)
946 if (table->needs_reopen_or_name_lock())
948 if (flags & DRIZZLE_LOCK_IGNORE_FLUSH)
951 open_tables.version= table->getShare()->getVersion();
956 if (table->open_placeholder && table->
in_use ==
this)
958 my_error(ER_UPDATE_TABLE_USED, MYF(0), table->getShare()->getTableName());
971 close_old_data_files(
false,
false);
988 if (table->
in_use !=
this)
991 wait_for_condition(table::Cache::mutex(), COND_refresh);
992 scopedLock.release();
1012 table::getUnused().unlink(static_cast<table::Concurrent *>(table));
1019 table::getUnused().cull();
1021 if (table_list->isCreate())
1023 identifier::Table lock_table_identifier(table_list->getSchemaName(), table_list->getTableName(), message::Table::STANDARD);
1025 if (not plugin::StorageEngine::doesTableExist(*
this, lock_table_identifier))
1030 table= &table_cache_insert_placeholder(lock_table_identifier);
1036 table->open_placeholder=
true;
1037 table->setNext(open_tables.open_tables_);
1038 open_tables.open_tables_= table;
1047 table::Concurrent *new_table=
new table::Concurrent;
1049 if (new_table->open_unireg_entry(
this, alias, identifier))
1054 (void)table::Cache::insert(new_table);
1061 table->setNext(open_tables.open_tables_);
1062 open_tables.open_tables_= table;
1064 table->reginfo.lock_type= TL_READ;
1067 assert(table->getShare()->getTableCount() > 0 || table->getShare()->getType() != message::Table::STANDARD);
1070 if (strcmp(table->getAlias(), alias))
1072 table->setAlias(alias);
1076 table->tablenr= open_tables.current_tablenr++;
1077 table->used_fields= 0;
1078 table->const_table= 0;
1079 table->null_row=
false;
1080 table->maybe_null=
false;
1081 table->force_index=
false;
1082 table->status=STATUS_NO_RECORD;
1083 table->insert_values.clear();
1085 assert(!table->auto_increment_field_not_null);
1086 table->auto_increment_field_not_null=
false;
1091 table->pos_in_table_list= table_list;
1092 table->clear_column_bitmaps();
1093 assert(table->key_read == 0);
1118 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
1120 if (open_tables.lock)
1126 unlockTables(open_tables.lock);
1127 open_tables.lock= 0;
1135 for (
Table *table= open_tables.open_tables_; table ; table=table->getNext())
1137 if (table->getShare()->getCacheKey() == identifier.getKey())
1139 table->open_placeholder=
true;
1140 close_handle_and_leave_table_as_lock(table);
1166 bool Session::reopen_tables()
1168 Table *table,*next,**prev;
1170 Table **tables_ptr= 0;
1172 const uint32_t flags= DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN |
1173 DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK |
1174 DRIZZLE_LOCK_IGNORE_FLUSH;
1176 if (open_tables.open_tables_ == NULL)
1179 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
1187 for (table= open_tables.open_tables_; table ; table=table->getNext())
1191 tables=
new Table *[opens];
1196 prev= &open_tables.open_tables_;
1197 for (table= open_tables.open_tables_; table ; table=next)
1199 next= table->getNext();
1201 my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
1202 table::remove_table(static_cast<table::Concurrent *>(table));
1207 if (tables != tables_ptr)
1215 if (not lockTables(tables, (uint32_t) (tables_ptr - tables), flags))
1222 my_error(ER_LOCK_DEADLOCK, MYF(0));
1249 void Session::close_old_data_files(
bool morph_locks,
bool send_refresh)
1251 bool found= send_refresh;
1253 Table *table= open_tables.open_tables_;
1255 for (; table ; table=table->getNext())
1260 if (table->needs_reopen_or_name_lock())
1267 Table *ulcktbl= table;
1277 removeLock(ulcktbl);
1280 if ((ulcktbl != table) && ulcktbl->
db_stat)
1288 ulcktbl->open_placeholder=
true;
1289 close_handle_and_leave_table_as_lock(ulcktbl);
1295 table->open_placeholder=
true;
1297 close_handle_and_leave_table_as_lock(table);
1299 else if (table->open_placeholder && !morph_locks)
1312 table->open_placeholder=
false;
1347 Table *table,*next,**prev, *found= 0;
1357 for (table= session->open_tables.
open_tables_; table ; table=next)
1359 next=table->getNext();
1360 if (table->getShare()->getCacheKey() == identifier.getKey())
1377 table::remove_table(static_cast<table::Concurrent *>(table));
1383 prev= table->getNextPtr();
1404 for (table= session->open_tables.open_tables_; table ; table= table->getNext())
1406 if (table->getShare()->getCacheKey() == identifier.getKey())
1409 session->abortLock(table);
1445 int Session::open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags)
1447 TableList *tables= NULL;
1451 bool safe_to_ignore_table;
1453 open_tables.current_tablenr= 0;
1456 set_proc_info(
"Opening tables");
1462 for (tables= *start; tables ;tables= tables->next_global)
1464 safe_to_ignore_table=
false;
1472 if (tables->derived)
1483 identifier::Table the_table(tables->getSchemaName(), tables->getTableName());
1484 if (not plugin::Authorization::isAuthorized(*user(), the_table))
1495 if (tables->table == NULL)
1496 tables->table= openTable(tables, &refresh, flags);
1498 if (tables->table == NULL)
1516 close_tables_for_reopen(start);
1520 if (safe_to_ignore_table)
1526 if (tables->lock_type != TL_UNLOCK)
1528 if (tables->lock_type == TL_WRITE_DEFAULT)
1529 tables->table->reginfo.lock_type= update_lock_default;
1530 else if (tables->table->getShare()->getType() == message::Table::STANDARD)
1531 tables->table->reginfo.lock_type= tables->lock_type;
1537 if (result && tables)
1543 tables->table= NULL;
1574 Table *Session::openTableLock(TableList *table_list, thr_lock_type lock_type)
1579 set_proc_info(
"Opening table");
1580 open_tables.current_tablenr= 0;
1581 while (!(table= openTable(table_list, &refresh)) && refresh) ;
1585 table_list->lock_type= lock_type;
1586 table_list->table= table;
1588 assert(open_tables.lock == 0);
1589 if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK)
1591 if (not (open_tables.lock= lockTables(&table_list->table, 1, 0)))
1629 int Session::lock_tables(TableList *tables, uint32_t count,
bool *need_reopen)
1635 *need_reopen=
false;
1640 assert(not open_tables.lock);
1643 Table** ptr=start=
new (mem) Table*[count];
1644 for (TableList* table= tables; table; table= table->next_global)
1646 if (!table->placeholder())
1647 *(ptr++)= table->table;
1649 if (not (open_tables.lock= lockTables(start, (uint32_t) (ptr - start), DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN)))
1677 Table* Session::open_temporary_table(
const identifier::Table &identifier,
bool link_in_list)
1679 assert(identifier.isTmp());
1680 table::Temporary *new_tmp_table=
new table::Temporary(identifier.getType(), identifier,
1681 identifier.getPath().c_str(),
static_cast<uint32_t
>(identifier.getPath().length()));
1685 if (new_tmp_table->getMutableShare()->open_table_def(*
this, identifier) ||
1686 new_tmp_table->getMutableShare()->open_table_from_share(
this, identifier, identifier.getTableName().c_str(),
1687 (uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX), ha_open_options, *new_tmp_table))
1690 delete new_tmp_table->getMutableShare();
1691 delete new_tmp_table;
1695 new_tmp_table->reginfo.lock_type= TL_WRITE;
1700 new_tmp_table->setNext(open_tables.temporary_tables);
1701 if (new_tmp_table->getNext())
1703 new_tmp_table->getNext()->setPrev(new_tmp_table);
1705 open_tables.temporary_tables= new_tmp_table;
1706 open_tables.temporary_tables->setPrev(0);
1708 new_tmp_table->pos_in_table_list= 0;
1710 return new_tmp_table;
1724 Field *not_found_field= (Field*) 0x1;
1725 Field *view_ref_found= (Field*) 0x2;
1727 static void update_field_dependencies(Session *session, Field *field, Table *table)
1729 if (session->mark_used_columns != MARK_COLUMNS_NONE)
1731 boost::dynamic_bitset<> *current_bitmap= NULL;
1738 table->covering_keys&= field->part_of_key;
1739 table->merge_keys|= field->part_of_key;
1741 if (session->mark_used_columns == MARK_COLUMNS_READ)
1743 current_bitmap= table->read_set;
1747 current_bitmap= table->write_set;
1751 if (current_bitmap->test(field->position()))
1753 if (session->mark_used_columns == MARK_COLUMNS_WRITE)
1754 session->dup_field= field;
1757 table->used_fields++;
1791 find_field_in_natural_join(Session *session, TableList *table_ref,
1792 const char *name, uint32_t , Item **,
1793 bool, TableList **actual_table)
1795 List<Natural_join_column>::iterator field_it(table_ref->join_columns->begin());
1796 Natural_join_column *nj_col, *curr_nj_col;
1799 assert(table_ref->is_natural_join && table_ref->join_columns);
1800 assert(*actual_table == NULL);
1802 for (nj_col= NULL, curr_nj_col= field_it++; curr_nj_col; curr_nj_col= field_it++)
1804 if (!system_charset_info->strcasecmp(curr_nj_col->name(), name))
1808 my_error(ER_NON_UNIQ_ERROR, MYF(0), name, session->where());
1811 nj_col= curr_nj_col;
1818 assert(nj_col->table_ref->table == nj_col->table_field->getTable());
1819 found_field= nj_col->table_field;
1820 update_field_dependencies(session, found_field, nj_col->table_ref->table);
1823 *actual_table= nj_col->table_ref;
1825 return(found_field);
1848 find_field_in_table(Session *session, Table *table,
const char *name, uint32_t length,
1849 bool allow_rowid, uint32_t *cached_field_index_ptr)
1851 Field **field_ptr, *field;
1852 uint32_t cached_field_index= *cached_field_index_ptr;
1855 if (cached_field_index < table->getShare()->sizeFields()
1856 && not system_charset_info->strcasecmp(table->getField(cached_field_index)->field_name, name))
1858 field_ptr= table->getFields() + cached_field_index;
1860 else if (table->getShare()->getNamedFieldSize())
1862 field_ptr= table->getMutableShare()->getNamedField(std::string(name, length));
1869 field_ptr= (table->getFields() + table->getShare()->positionFields(field_ptr));
1874 if (!(field_ptr= table->getFields()))
1876 for (; *field_ptr; ++field_ptr)
1877 if (not system_charset_info->strcasecmp((*field_ptr)->field_name, name))
1881 if (field_ptr && *field_ptr)
1883 *cached_field_index_ptr= field_ptr - table->getFields();
1889 system_charset_info->strcasecmp(name,
"_rowid") ||
1890 table->getShare()->rowid_field_offset == 0)
1892 field= table->getField(table->getShare()->rowid_field_offset-1);
1895 update_field_dependencies(session, field, table);
1943 find_field_in_table_ref(Session *session, TableList *table_list,
1944 const char *name, uint32_t length,
1945 const char *item_name,
const char *db_name,
1946 const char *table_name, Item **ref,
1948 uint32_t *cached_field_index_ptr,
1949 bool register_tree_change, TableList **actual_table)
1953 assert(table_list->alias);
1974 (!table_list->getNestedJoin()) &&
1980 table_name && table_name[0] &&
1981 (table_alias_charset->strcasecmp(table_list->alias, table_name) ||
1982 (db_name && db_name[0] && table_list->getSchemaName() && table_list->getSchemaName()[0] &&
1983 strcmp(db_name, table_list->getSchemaName()))))
1986 *actual_table= NULL;
1988 if (!table_list->getNestedJoin())
1991 assert(table_list->table);
1992 if ((fld= find_field_in_table(session, table_list->table, name, length,
1994 cached_field_index_ptr)))
1995 *actual_table= table_list;
2006 if (table_name && table_name[0])
2008 List<TableList>::iterator it(table_list->getNestedJoin()->join_list.begin());
2010 while ((table= it++))
2012 if ((fld= find_field_in_table_ref(session, table, name, length, item_name,
2013 db_name, table_name, ref,
2015 cached_field_index_ptr,
2016 register_tree_change, actual_table)))
2027 fld= find_field_in_natural_join(session, table_list, name, length, ref,
2028 register_tree_change, actual_table);
2033 if (session->mark_used_columns != MARK_COLUMNS_NONE)
2040 Field *field_to_set= NULL;
2041 if (fld == view_ref_found)
2043 Item *it= (*ref)->real_item();
2044 if (it->type() == Item::FIELD_ITEM)
2045 field_to_set= ((Item_field*)it)->field;
2048 if (session->mark_used_columns == MARK_COLUMNS_READ)
2049 it->walk(&Item::register_field_in_read_map, 1, (
unsigned char *) 0);
2056 Table *table= field_to_set->getTable();
2057 if (session->mark_used_columns == MARK_COLUMNS_READ)
2058 table->setReadSet(field_to_set->position());
2060 table->setWriteSet(field_to_set->position());
2102 find_field_in_tables(Session *session, Item_ident *item,
2103 TableList *first_table, TableList *last_table,
2104 Item **ref, find_item_error_report_type report_error,
2105 bool register_tree_change)
2108 const char *db= item->db_name;
2109 const char *table_name= item->table_name;
2110 const char *name= item->field_name;
2111 uint32_t length=(uint32_t) strlen(name);
2112 char name_buff[NAME_LEN+1];
2113 TableList *cur_table= first_table;
2114 TableList *actual_table;
2117 if (!table_name || !table_name[0])
2123 allow_rowid= table_name || (cur_table && !cur_table->next_local);
2125 if (item->cached_table)
2136 TableList *table_ref= item->cached_table;
2142 if (table_ref->table)
2143 found= find_field_in_table(session, table_ref->table, name, length,
2144 true, &(item->cached_field_index));
2146 found= find_field_in_table_ref(session, table_ref, name, length, item->name,
2148 true, &(item->cached_field_index),
2149 register_tree_change,
2158 Select_Lex *current_sel= session->lex().current_select;
2159 Select_Lex *last_select= table_ref->select_lex;
2164 if (current_sel != last_select)
2179 strncpy(name_buff, db,
sizeof(name_buff)-1);
2180 files_charset_info->casedn_str(name_buff);
2185 last_table= last_table->next_name_resolution_table;
2187 for (; cur_table != last_table ;
2188 cur_table= cur_table->next_name_resolution_table)
2190 Field *cur_field= find_field_in_table_ref(session, cur_table, name, length,
2191 item->name, db, table_name, ref,
2193 &(item->cached_field_index),
2194 register_tree_change,
2202 item->cached_table= found ? 0 : actual_table;
2204 assert(session->where());
2214 if (report_error == REPORT_ALL_ERRORS ||
2215 report_error == IGNORE_EXCEPT_NON_UNIQUE)
2216 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2217 table_name ? item->full_name() : name, session->where());
2234 if (table_name && (cur_table == first_table) &&
2235 (report_error == REPORT_ALL_ERRORS ||
2236 report_error == REPORT_EXCEPT_NON_UNIQUE))
2238 char buff[NAME_LEN*2+1];
2243 assert(strlen(db) <= NAME_LEN);
2244 assert(strlen(table_name) <= NAME_LEN);
2247 strcat(buff, table_name);
2250 my_error(ER_UNKNOWN_TABLE, MYF(0), table_name, session->where());
2254 if (report_error == REPORT_ALL_ERRORS ||
2255 report_error == REPORT_EXCEPT_NON_UNIQUE)
2256 my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(), session->where());
2258 found= not_found_field;
2298 Item **not_found_item= (Item**) 0x1;
2302 find_item_in_list(Session *session,
2303 Item *find, List<Item> &items, uint32_t *counter,
2304 find_item_error_report_type report_error,
2305 enum_resolution_type *resolution)
2307 List<Item>::iterator li(items.begin());
2308 Item **found=0, **found_unaliased= 0, *item;
2309 const char *db_name=0;
2310 const char *field_name=0;
2311 const char *table_name=0;
2312 bool found_unaliased_non_uniq= 0;
2317 bool is_ref_by_name= 0;
2318 uint32_t unaliased_counter= 0;
2320 *resolution= NOT_RESOLVED;
2322 is_ref_by_name= (find->type() == Item::FIELD_ITEM ||
2323 find->type() == Item::REF_ITEM);
2326 field_name= ((Item_ident*) find)->field_name;
2327 table_name= ((Item_ident*) find)->table_name;
2328 db_name= ((Item_ident*) find)->db_name;
2331 for (uint32_t i= 0; (item=li++); i++)
2333 if (field_name && item->real_item()->type() == Item::FIELD_ITEM)
2335 Item_ident *item_field= (Item_ident*) item;
2343 if (!item_field->name)
2364 if (item_field->field_name && item_field->table_name &&
2365 not system_charset_info->strcasecmp(item_field->field_name, field_name) &&
2366 not table_alias_charset->strcasecmp(item_field->table_name, table_name) &&
2367 (!db_name || (item_field->db_name && !strcmp(item_field->db_name, db_name))))
2369 if (found_unaliased)
2371 if ((*found_unaliased)->eq(item, 0))
2378 if (report_error != IGNORE_ERRORS)
2379 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2380 find->full_name(), session->where());
2383 found_unaliased= li.ref();
2384 unaliased_counter= i;
2385 *resolution= RESOLVED_IGNORING_ALIAS;
2392 int fname_cmp= system_charset_info->strcasecmp(item_field->field_name, field_name);
2393 if (not system_charset_info->strcasecmp(item_field->name, field_name))
2404 if ((*found)->eq(item, 0))
2406 if (report_error != IGNORE_ERRORS)
2407 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2408 find->full_name(), session->where());
2413 *resolution= fname_cmp ? RESOLVED_AGAINST_ALIAS : RESOLVED_WITH_NO_ALIAS;
2415 else if (!fname_cmp)
2423 if (found_unaliased)
2425 if ((*found_unaliased)->eq(item, 0))
2427 found_unaliased_non_uniq= 1;
2429 found_unaliased= li.ref();
2430 unaliased_counter= i;
2434 else if (!table_name)
2436 if (is_ref_by_name && find->name && item->name &&
2437 not system_charset_info->strcasecmp(item->name,find->name))
2441 *resolution= RESOLVED_AGAINST_ALIAS;
2444 else if (find->eq(item,0))
2448 *resolution= RESOLVED_IGNORING_ALIAS;
2455 if (found_unaliased_non_uniq)
2457 if (report_error != IGNORE_ERRORS)
2458 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2459 find->full_name(), session->where());
2462 if (found_unaliased)
2464 found= found_unaliased;
2465 *counter= unaliased_counter;
2466 *resolution= RESOLVED_BEHIND_ALIAS;
2471 if (report_error != REPORT_EXCEPT_NOT_FOUND)
2473 if (report_error == REPORT_ALL_ERRORS)
2474 my_error(ER_BAD_FIELD_ERROR, MYF(0),
2475 find->full_name(), session->where());
2479 return (Item **) not_found_item;
2501 test_if_string_in_list(
const char *find, List<String> *str_list)
2503 List<String>::iterator str_list_it(str_list->begin());
2505 size_t find_length= strlen(find);
2506 while ((curr_str= str_list_it++))
2508 if (find_length != curr_str->length())
2510 if (not system_charset_info->strcasecmp(find, curr_str->ptr()))
2536 static void set_new_item_local_context(Session *session, Item_ident *item, TableList *table_ref)
2538 Name_resolution_context* context=
new (session->mem_root) Name_resolution_context;
2540 context->first_name_resolution_table= context->last_name_resolution_table= table_ref;
2541 item->context= context;
2577 mark_common_columns(Session *session, TableList *table_ref_1, TableList *table_ref_2,
2578 List<String> *using_fields, uint32_t *found_using_fields)
2580 Field_iterator_table_ref it_1, it_2;
2581 Natural_join_column *nj_col_1, *nj_col_2;
2582 bool first_outer_loop=
true;
2587 TableList *leaf_1= (table_ref_1->getNestedJoin() &&
2588 ! table_ref_1->is_natural_join) ?
2590 TableList *leaf_2= (table_ref_2->getNestedJoin() &&
2591 ! table_ref_2->is_natural_join) ?
2594 *found_using_fields= 0;
2596 for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
2599 const char *field_name_1;
2601 bool is_using_column_1;
2602 if (!(nj_col_1= it_1.get_or_create_column_ref(leaf_1)))
2604 field_name_1= nj_col_1->name();
2605 is_using_column_1= using_fields &&
2606 test_if_string_in_list(field_name_1, using_fields);
2616 for (it_2.set(table_ref_2); !it_2.end_of_fields(); it_2.next())
2618 Natural_join_column *cur_nj_col_2;
2619 const char *cur_field_name_2;
2620 if (!(cur_nj_col_2= it_2.get_or_create_column_ref(leaf_2)))
2622 cur_field_name_2= cur_nj_col_2->name();
2635 if (!system_charset_info->strcasecmp(field_name_1, cur_field_name_2))
2637 if (cur_nj_col_2->is_common ||
2638 (found && (!using_fields || is_using_column_1)))
2640 my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1, session->where());
2643 nj_col_2= cur_nj_col_2;
2647 if (first_outer_loop && leaf_2)
2653 leaf_2->is_join_columns_complete=
true;
2654 first_outer_loop=
false;
2664 if (nj_col_2 && (!using_fields ||is_using_column_1))
2666 Item *item_1= nj_col_1->create_item(session);
2667 Item *item_2= nj_col_2->create_item(session);
2668 Field *field_1= nj_col_1->field();
2669 Field *field_2= nj_col_2->field();
2671 if (!item_1 || !item_2)
2678 assert(item_1->type() == Item::FIELD_ITEM ||
2679 item_1->type() == Item::REF_ITEM);
2680 assert(item_2->type() == Item::FIELD_ITEM ||
2681 item_2->type() == Item::REF_ITEM);
2687 Item_ident* item_ident_1= (Item_ident*) item_1;
2688 Item_ident* item_ident_2= (Item_ident*) item_2;
2695 set_new_item_local_context(session, item_ident_1, nj_col_1->table_ref);
2696 set_new_item_local_context(session, item_ident_2, nj_col_2->table_ref);
2698 Item_func_eq* eq_cond=
new Item_func_eq(item_ident_1, item_ident_2);
2705 add_join_on((table_ref_1->outer_join & JOIN_TYPE_RIGHT ?
2706 table_ref_1 : table_ref_2),
2709 nj_col_1->is_common= nj_col_2->is_common=
true;
2713 Table *table_1= nj_col_1->table_ref->table;
2715 table_1->setReadSet(field_1->position());
2716 table_1->covering_keys&= field_1->part_of_key;
2717 table_1->merge_keys|= field_1->part_of_key;
2721 Table *table_2= nj_col_2->table_ref->table;
2723 table_2->setReadSet(field_2->position());
2724 table_2->covering_keys&= field_2->part_of_key;
2725 table_2->merge_keys|= field_2->part_of_key;
2728 if (using_fields != NULL)
2729 ++(*found_using_fields);
2733 leaf_1->is_join_columns_complete=
true;
2783 store_natural_using_join_columns(Session *session,
2784 TableList *natural_using_join,
2785 TableList *table_ref_1,
2786 TableList *table_ref_2,
2787 List<String> *using_fields,
2788 uint32_t found_using_fields)
2790 Field_iterator_table_ref it_1, it_2;
2791 Natural_join_column *nj_col_1, *nj_col_2;
2793 assert(!natural_using_join->join_columns);
2795 List<Natural_join_column>* non_join_columns=
new List<Natural_join_column>;
2796 natural_using_join->join_columns=
new List<Natural_join_column>;
2799 for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
2801 nj_col_1= it_1.get_natural_column_ref();
2802 if (nj_col_1->is_common)
2804 natural_using_join->join_columns->push_back(nj_col_1);
2806 nj_col_1->is_common=
false;
2809 non_join_columns->push_back(nj_col_1);
2817 if (using_fields && found_using_fields < using_fields->size())
2819 List<String>::iterator using_fields_it(using_fields->begin());
2820 while (String* using_field_name= using_fields_it++)
2822 const char *using_field_name_ptr= using_field_name->c_ptr();
2823 List<Natural_join_column>::iterator it(natural_using_join->join_columns->begin());
2827 Natural_join_column* common_field= it++;
2828 if (not common_field)
2830 my_error(ER_BAD_FIELD_ERROR, MYF(0), using_field_name_ptr, session->where());
2833 if (!system_charset_info->strcasecmp(common_field->name(), using_field_name_ptr))
2840 for (it_2.set(table_ref_2); !it_2.end_of_fields(); it_2.next())
2842 nj_col_2= it_2.get_natural_column_ref();
2843 if (!nj_col_2->is_common)
2844 non_join_columns->push_back(nj_col_2);
2848 nj_col_2->is_common=
false;
2852 if (non_join_columns->size() > 0)
2853 natural_using_join->join_columns->concat(non_join_columns);
2854 natural_using_join->is_join_columns_complete=
true;
2891 store_top_level_join_columns(Session *session, TableList *table_ref,
2892 TableList *left_neighbor,
2893 TableList *right_neighbor)
2896 if (table_ref->getNestedJoin())
2898 List<TableList>::iterator nested_it(table_ref->getNestedJoin()->join_list.begin());
2899 TableList *same_level_left_neighbor= nested_it++;
2900 TableList *same_level_right_neighbor= NULL;
2902 TableList *real_left_neighbor, *real_right_neighbor;
2904 while (same_level_left_neighbor)
2906 TableList *cur_table_ref= same_level_left_neighbor;
2907 same_level_left_neighbor= nested_it++;
2919 if (same_level_left_neighbor &&
2920 cur_table_ref->outer_join & JOIN_TYPE_RIGHT)
2923 assert(table_ref->getNestedJoin()->join_list.size() == 2);
2924 std::swap(same_level_left_neighbor, cur_table_ref);
2931 real_left_neighbor= (same_level_left_neighbor) ?
2932 same_level_left_neighbor : left_neighbor;
2933 real_right_neighbor= (same_level_right_neighbor) ?
2934 same_level_right_neighbor : right_neighbor;
2936 if (cur_table_ref->getNestedJoin() &&
2937 store_top_level_join_columns(session, cur_table_ref, real_left_neighbor, real_right_neighbor))
2939 same_level_right_neighbor= cur_table_ref;
2947 if (table_ref->is_natural_join)
2949 assert(table_ref->getNestedJoin() &&
2950 table_ref->getNestedJoin()->join_list.size() == 2);
2951 List<TableList>::iterator operand_it(table_ref->getNestedJoin()->join_list.begin());
2957 TableList *table_ref_2= operand_it++;
2958 TableList *table_ref_1= operand_it++;
2959 List<String> *using_fields= table_ref->join_using_fields;
2960 uint32_t found_using_fields;
2966 if (table_ref_2->outer_join & JOIN_TYPE_RIGHT)
2967 std::swap(table_ref_1, table_ref_2);
2968 if (mark_common_columns(session, table_ref_1, table_ref_2,
2969 using_fields, &found_using_fields))
2977 if (table_ref_1->outer_join & JOIN_TYPE_RIGHT)
2978 std::swap(table_ref_1, table_ref_2);
2979 if (store_natural_using_join_columns(session, table_ref, table_ref_1,
2980 table_ref_2, using_fields,
2981 found_using_fields))
2990 table_ref_1->natural_join= table_ref_2->natural_join= NULL;
2993 if (table_ref_2->outer_join &&
2994 !table_ref_1->on_expr && !table_ref_2->on_expr)
2995 table_ref_2->on_expr=
new Item_int((int64_t) 1,1);
3000 TableList *last_leaf_on_the_left;
3001 last_leaf_on_the_left= left_neighbor->last_leaf_for_name_resolution();
3002 last_leaf_on_the_left->next_name_resolution_table= table_ref;
3006 TableList *first_leaf_on_the_right;
3007 first_leaf_on_the_right= right_neighbor->first_leaf_for_name_resolution();
3008 table_ref->next_name_resolution_table= first_leaf_on_the_right;
3011 table_ref->next_name_resolution_table= NULL;
3041 static bool setup_natural_join_row_types(Session *session,
3042 List<TableList> *from_clause,
3043 Name_resolution_context *context)
3045 session->setWhere(
"from clause");
3046 if (from_clause->size() == 0)
3049 List<TableList>::iterator table_ref_it(from_clause->begin());
3050 TableList *table_ref;
3052 TableList *left_neighbor;
3054 TableList *right_neighbor= NULL;
3057 for (left_neighbor= table_ref_it++; left_neighbor ; )
3059 table_ref= left_neighbor;
3060 left_neighbor= table_ref_it++;
3061 if (store_top_level_join_columns(session, table_ref, left_neighbor, right_neighbor))
3065 TableList *first_leaf_on_the_right;
3066 first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
3067 left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
3069 right_neighbor= table_ref;
3078 assert(right_neighbor);
3079 context->first_name_resolution_table=
3080 right_neighbor->first_leaf_for_name_resolution();
3090 int setup_wild(Session *session, List<Item> &fields,
3091 List<Item> *sum_func_list,
3098 List<Item>::iterator it(fields.begin());
3100 session->lex().current_select->cur_pos_in_select_list= 0;
3101 while (wild_num && (item= it++))
3103 if (item->type() == Item::FIELD_ITEM &&
3104 ((Item_field*) item)->field_name &&
3105 ((Item_field*) item)->field_name[0] ==
'*' &&
3106 !((Item_field*) item)->field)
3108 uint32_t elem= fields.size();
3109 bool any_privileges= ((Item_field *) item)->any_privileges;
3110 Item_subselect *subsel= session->lex().current_select->master_unit()->item;
3112 subsel->substype() == Item_subselect::EXISTS_SUBS)
3119 it.replace(
new Item_int(
"Not_used", (int64_t) 1,
3120 MY_INT64_NUM_DECIMAL_DIGITS));
3122 else if (insert_fields(session, ((Item_field*) item)->context,
3123 ((Item_field*) item)->db_name,
3124 ((Item_field*) item)->table_name, &it,
3136 sum_func_list->set_size(sum_func_list->size() + fields.size() - elem);
3141 session->lex().current_select->cur_pos_in_select_list++;
3143 session->lex().current_select->cur_pos_in_select_list= UNDEF_POS;
3152 bool setup_fields(Session *session, Item **ref_pointer_array,
3153 List<Item> &fields, enum_mark_columns mark_used_columns,
3154 List<Item> *sum_func_list,
bool allow_sum_func)
3157 enum_mark_columns save_mark_used_columns= session->mark_used_columns;
3158 nesting_map save_allow_sum_func= session->lex().allow_sum_func;
3159 List<Item>::iterator it(fields.begin());
3160 bool save_is_item_list_lookup;
3162 session->mark_used_columns= mark_used_columns;
3164 session->lex().allow_sum_func|= 1 << session->lex().current_select->nest_level;
3165 session->setWhere(Session::DEFAULT_WHERE);
3166 save_is_item_list_lookup= session->lex().current_select->is_item_list_lookup;
3167 session->lex().current_select->is_item_list_lookup= 0;
3179 if (ref_pointer_array)
3181 memset(ref_pointer_array, 0,
sizeof(Item *) * fields.size());
3184 Item **ref= ref_pointer_array;
3185 session->lex().current_select->cur_pos_in_select_list= 0;
3186 while ((item= it++))
3188 if ((!item->fixed && item->fix_fields(session, it.ref())) || (item= *(it.ref()))->check_cols(1))
3190 session->lex().current_select->is_item_list_lookup= save_is_item_list_lookup;
3191 session->lex().allow_sum_func= save_allow_sum_func;
3192 session->mark_used_columns= save_mark_used_columns;
3197 if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
3199 item->split_sum_func(session, ref_pointer_array, *sum_func_list);
3200 session->used_tables|= item->used_tables();
3201 session->lex().current_select->cur_pos_in_select_list++;
3203 session->lex().current_select->is_item_list_lookup= save_is_item_list_lookup;
3204 session->lex().current_select->cur_pos_in_select_list= UNDEF_POS;
3206 session->lex().allow_sum_func= save_allow_sum_func;
3207 session->mark_used_columns= save_mark_used_columns;
3208 return(test(session->is_error()));
3223 static TableList **make_leaves_list(TableList **list, TableList *tables)
3225 for (TableList *table= tables; table; table= table->next_local)
3263 bool setup_tables(Session *session, Name_resolution_context *context,
3264 List<TableList> *from_clause, TableList *tables,
3265 TableList **leaves,
bool select_insert)
3267 assert((select_insert && !tables->next_name_resolution_table) || !tables ||
3268 (context->table_list && context->first_name_resolution_table));
3273 TableList *first_select_table= select_insert ? tables->next_local : NULL;
3276 make_leaves_list(leaves, tables);
3278 uint32_t tablenr= 0;
3279 for (TableList* table_list= *leaves; table_list; table_list= table_list->next_leaf, tablenr++)
3281 Table *table= table_list->table;
3282 table->pos_in_table_list= table_list;
3283 if (first_select_table &&
3284 table_list->top_table() == first_select_table)
3287 first_select_table= 0;
3290 table->setup_table_map(table_list, tablenr);
3291 if (table_list->process_index_hints(table))
3294 if (tablenr > MAX_TABLES)
3296 my_error(ER_TOO_MANY_TABLES,MYF(0),MAX_TABLES);
3301 if (setup_natural_join_row_types(session, from_clause, context))
3331 bool setup_tables_and_check_access(Session *session,
3332 Name_resolution_context *context,
3333 List<TableList> *from_clause,
3338 TableList *leaves_tmp= NULL;
3340 if (setup_tables(session, context, from_clause, tables, &leaves_tmp, select_insert))
3344 *leaves= leaves_tmp;
3369 insert_fields(Session *session, Name_resolution_context *context,
const char *db_name,
3370 const char *table_name, List<Item>::iterator *it,
3373 Field_iterator_table_ref field_iterator;
3375 char name_buff[NAME_LEN+1];
3384 strncpy(name_buff, db_name,
sizeof(name_buff)-1);
3385 files_charset_info->casedn_str(name_buff);
3396 for (TableList *tables= (table_name ? context->table_list :
3397 context->first_name_resolution_table);
3399 tables= (table_name ? tables->next_local :
3400 tables->next_name_resolution_table)
3404 Table *table= tables->table;
3406 assert(tables->is_leaf_for_name_resolution());
3408 if ((table_name && table_alias_charset->strcasecmp(table_name, tables->alias)) ||
3409 (db_name && system_charset_info->strcasecmp(tables->getSchemaName(),db_name)))
3417 session->used_tables|= table->map;
3425 field_iterator.set(tables);
3427 for (; !field_iterator.end_of_fields(); field_iterator.next())
3429 Item *item= field_iterator.create_item(session);
3441 if ((field= field_iterator.field()))
3444 field->getTable()->setReadSet(field->position());
3447 table->covering_keys&= field->part_of_key;
3448 table->merge_keys|= field->part_of_key;
3450 if (tables->is_natural_join)
3457 Natural_join_column *nj_col;
3458 if (!(nj_col= field_iterator.get_natural_column_ref()))
3460 assert(nj_col->table_field);
3461 field_table= nj_col->table_ref->table;
3464 session->used_tables|= field_table->map;
3465 field_table->covering_keys&= field->part_of_key;
3466 field_table->merge_keys|= field->part_of_key;
3467 field_table->used_fields++;
3473 session->used_tables|= item->used_tables();
3476 session->lex().current_select->cur_pos_in_select_list++;
3485 table->used_fields= table->getShare()->sizeFields();
3497 my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
3501 my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name);
3526 int Session::setup_conds(TableList *leaves, COND **conds)
3528 Session *session=
this;
3529 Select_Lex *select_lex= session->lex().current_select;
3530 TableList *table= NULL;
3531 void *save_session_marker= session->session_marker;
3540 bool save_is_item_list_lookup= select_lex->is_item_list_lookup;
3541 select_lex->is_item_list_lookup= 0;
3543 session->mark_used_columns= MARK_COLUMNS_READ;
3544 select_lex->cond_count= 0;
3545 select_lex->between_count= 0;
3546 select_lex->max_equal_elems= 0;
3548 session->session_marker= (
void*)1;
3551 session->setWhere(
"where clause");
3552 if ((!(*conds)->fixed && (*conds)->fix_fields(session, conds)) ||
3553 (*conds)->check_cols(1))
3556 session->session_marker= save_session_marker;
3562 for (table= leaves; table; table= table->next_leaf)
3564 TableList *embedded;
3565 TableList *embedding= table;
3568 embedded= embedding;
3569 if (embedded->on_expr)
3572 session->session_marker= (
void*)embedded;
3573 session->setWhere(
"on clause");
3574 if ((!embedded->on_expr->fixed && embedded->on_expr->fix_fields(session, &embedded->on_expr)) ||
3575 embedded->on_expr->check_cols(1))
3577 select_lex->cond_count++;
3579 embedding= embedded->getEmbedding();
3582 &embedding->getNestedJoin()->join_list.front() == embedded);
3585 session->session_marker= save_session_marker;
3587 session->lex().current_select->is_item_list_lookup= save_is_item_list_lookup;
3588 return(test(session->is_error()));
3591 select_lex->is_item_list_lookup= save_is_item_list_lookup;
3623 fill_record(Session *session, List<Item> &fields, List<Item> &values,
bool ignore_errors)
3625 List<Item>::iterator f(fields.begin());
3626 List<Item>::iterator v(values.begin());
3641 field=
static_cast<Item_field *
>(f++);
3642 table= field->field->getTable();
3643 table->auto_increment_field_not_null=
false;
3647 while ((field= static_cast<Item_field *>(f++)))
3651 Field *rfield= field->field;
3652 table= rfield->getTable();
3654 if (rfield == table->next_number_field)
3655 table->auto_increment_field_not_null=
true;
3656 if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
3658 my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
3660 table->auto_increment_field_not_null=
false;
3666 return session->is_error();
3689 bool fill_record(Session *session, Field **ptr, List<Item> &values,
bool)
3691 List<Item>::iterator v(values.begin());
3706 table= (*ptr)->getTable();
3707 table->auto_increment_field_not_null=
false;
3710 while ((field = *ptr++) && ! session->is_error())
3713 table= field->getTable();
3715 if (field == table->next_number_field)
3717 table->auto_increment_field_not_null=
true;
3720 if (value->save_in_field(field, 0) < 0)
3723 table->auto_increment_field_not_null=
false;
3729 return(session->is_error());
3733 void drizzle_rm_tmp_tables()
3735 assert(drizzle_tmpdir.size());
3736 Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
3737 session->thread_stack= (
char*) session.get();
3738 session->storeGlobals();
3739 plugin::StorageEngine::removeLostTemporaryTables(*session, drizzle_tmpdir.c_str());
3748 pthread_kill(signal_thread, SIGTERM);
3749 shutdown_in_progress=
true;