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()->getTableIdentifier().getCatalog(), 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(catalog().identifier(), 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()->getTableIdentifier().getCatalog(),
477 table->getShare()->getSchemaName(),
478 table->getShare()->getTableName(),
479 table->getShare()->getPath()));
484 void Open_tables_state::doGetTableIdentifiers(CachedDirectory &,
485 const identifier::Schema &schema_identifier,
486 identifier::table::vector &set_of_identifiers)
488 doGetTableIdentifiers(schema_identifier, set_of_identifiers);
491 bool Open_tables_state::doDoesTableExist(
const identifier::Table &identifier)
493 for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
495 if (table->getShare()->getType() == message::Table::TEMPORARY)
497 if (identifier.getKey() == table->getShare()->getCacheKey())
507 int Open_tables_state::doGetTableDefinition(
const identifier::Table &identifier,
508 message::Table &table_proto)
510 for (Table *table= getTemporaryTables() ; table ; table= table->getNext())
512 if (table->getShare()->getType() == message::Table::TEMPORARY)
514 if (identifier.getKey() == table->getShare()->getCacheKey())
516 table_proto.CopyFrom(*(table->getShare()->getTableMessage()));
526 Table *Open_tables_state::find_temporary_table(
const identifier::Table &identifier)
528 for (Table *table= temporary_tables ; table ; table= table->getNext())
530 if (identifier.getKey() == table->getShare()->getCacheKey())
566 Table* table= find_temporary_table(identifier);
571 if (table->query_id && table->query_id != session_.getQueryId())
573 my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
576 close_temporary_table(table);
591 void Session::unlink_open_table(
Table *find)
595 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
604 for (prev= &open_tables.open_tables_; *prev; )
608 if (list->getShare()->getCacheKey() == find_key)
611 *prev= list->getNext();
614 table::remove_table(static_cast<table::Concurrent *>(list));
619 prev= list->getNextPtr();
649 if (table->getShare()->getType())
651 open_tables.close_temporary_table(table);
655 boost::mutex::scoped_lock scoped_lock(table::Cache::mutex());
660 unlink_open_table(table);
661 (void)plugin::StorageEngine::dropTable(*
this, identifier);
677 void Session::wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond)
680 const char *saved_proc_info;
681 mysys_var->current_mutex= &mutex;
682 mysys_var->current_cond= &cond;
683 saved_proc_info= get_proc_info();
684 set_proc_info(
"Waiting for table");
696 boost::mutex::scoped_lock scopedLock(mutex, boost::adopt_lock_t());
699 cond.wait(scopedLock);
702 boost::mutex::scoped_lock mysys_scopedLock(mysys_var->mutex);
703 mysys_var->current_mutex= 0;
704 mysys_var->current_cond= 0;
705 set_proc_info(saved_proc_info);
724 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
732 message::Table::INTERNAL);
734 table::Cache::insert(table);
763 boost::mutex::scoped_lock scope_lock(table::Cache::mutex());
764 if (find_ptr(table::getCache(), key))
766 Table& table= table_cache_insert_placeholder(identifier);
767 table.open_placeholder=
true;
768 table.setNext(open_tables.open_tables_);
769 open_tables.open_tables_= &table;
806 Table *Session::openTable(
TableList *table_list,
bool *refresh, uint32_t flags)
809 const char *alias= table_list->alias;
812 assert(lex().is_lex_started);
821 if (check_stack_overrun(
this, STACK_MIN_SIZE_FOR_OPEN, (
unsigned char *)&alias))
831 identifier::Table identifier(catalog().identifier(),
832 table_list->getSchemaName(),
833 table_list->getTableName());
834 const identifier::Table::Key &key(identifier.getKey());
835 table::CacheRange ppp;
845 for (table= open_tables.getTemporaryTables(); table ; table=table->getNext())
847 if (table->getShare()->getCacheKey() == key)
857 my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
860 table->query_id= getQueryId();
868 if (flags & DRIZZLE_OPEN_TEMPORARY_ONLY)
870 my_error(ER_TABLE_UNKNOWN, identifier);
883 if (!open_tables.open_tables_)
885 open_tables.version= g_refresh_version;
887 else if ((open_tables.version != g_refresh_version) &&
888 ! (flags & DRIZZLE_LOCK_IGNORE_FLUSH))
913 boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
925 ppp= table::getCache().equal_range(key);
928 for (table::CacheMap::const_iterator iter= ppp.first; iter != ppp.second; ++iter, table= NULL)
952 if (table->needs_reopen_or_name_lock())
954 if (flags & DRIZZLE_LOCK_IGNORE_FLUSH)
957 open_tables.version= table->getShare()->getVersion();
962 if (table->open_placeholder && table->
in_use ==
this)
964 my_error(ER_UPDATE_TABLE_USED, MYF(0), table->getShare()->getTableName());
977 close_old_data_files(
false,
false);
994 if (table->
in_use !=
this)
997 wait_for_condition(table::Cache::mutex(), COND_refresh);
998 scopedLock.release();
1002 scopedLock.unlock();
1018 table::getUnused().unlink(static_cast<table::Concurrent *>(table));
1025 table::getUnused().cull();
1027 if (table_list->isCreate())
1029 identifier::Table lock_table_identifier(catalog().identifier(),
1030 table_list->getSchemaName(),
1031 table_list->getTableName(),
1032 message::Table::STANDARD);
1034 if (not plugin::StorageEngine::doesTableExist(*
this, lock_table_identifier))
1039 table= &table_cache_insert_placeholder(lock_table_identifier);
1045 table->open_placeholder=
true;
1046 table->setNext(open_tables.open_tables_);
1047 open_tables.open_tables_= table;
1056 table::Concurrent *new_table=
new table::Concurrent;
1058 if (new_table->open_unireg_entry(
this, alias, identifier))
1063 (void)table::Cache::insert(new_table);
1070 table->setNext(open_tables.open_tables_);
1071 open_tables.open_tables_= table;
1073 table->reginfo.lock_type= TL_READ;
1076 assert(table->getShare()->getTableCount() > 0 || table->getShare()->getType() != message::Table::STANDARD);
1079 if (strcmp(table->getAlias(), alias))
1081 table->setAlias(alias);
1085 table->tablenr= open_tables.current_tablenr++;
1086 table->used_fields= 0;
1087 table->const_table= 0;
1088 table->null_row=
false;
1089 table->maybe_null=
false;
1090 table->force_index=
false;
1091 table->status=STATUS_NO_RECORD;
1092 table->insert_values.clear();
1094 assert(!table->auto_increment_field_not_null);
1095 table->auto_increment_field_not_null=
false;
1100 table->pos_in_table_list= table_list;
1101 table->clear_column_bitmaps();
1102 assert(table->key_read == 0);
1127 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
1129 if (open_tables.lock)
1135 unlockTables(open_tables.lock);
1136 open_tables.lock= 0;
1144 for (
Table *table= open_tables.open_tables_; table ; table=table->getNext())
1146 if (table->getShare()->getCacheKey() == identifier.getKey())
1148 table->open_placeholder=
true;
1149 close_handle_and_leave_table_as_lock(table);
1175 bool Session::reopen_tables()
1177 Table *table,*next,**prev;
1179 Table **tables_ptr= 0;
1181 const uint32_t flags= DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN |
1182 DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK |
1183 DRIZZLE_LOCK_IGNORE_FLUSH;
1185 if (open_tables.open_tables_ == NULL)
1188 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
1196 for (table= open_tables.open_tables_; table ; table=table->getNext())
1200 tables=
new Table *[opens];
1205 prev= &open_tables.open_tables_;
1206 for (table= open_tables.open_tables_; table ; table=next)
1208 next= table->getNext();
1210 my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
1211 table::remove_table(static_cast<table::Concurrent *>(table));
1216 if (tables != tables_ptr)
1224 if (not lockTables(tables, (uint32_t) (tables_ptr - tables), flags))
1231 my_error(ER_LOCK_DEADLOCK, MYF(0));
1258 void Session::close_old_data_files(
bool morph_locks,
bool send_refresh)
1260 bool found= send_refresh;
1262 Table *table= open_tables.open_tables_;
1264 for (; table ; table=table->getNext())
1269 if (table->needs_reopen_or_name_lock())
1276 Table *ulcktbl= table;
1286 removeLock(ulcktbl);
1289 if ((ulcktbl != table) && ulcktbl->
db_stat)
1297 ulcktbl->open_placeholder=
true;
1298 close_handle_and_leave_table_as_lock(ulcktbl);
1304 table->open_placeholder=
true;
1306 close_handle_and_leave_table_as_lock(table);
1308 else if (table->open_placeholder && !morph_locks)
1321 table->open_placeholder=
false;
1356 Table *table,*next,**prev, *found= 0;
1366 for (table= session->open_tables.
open_tables_; table ; table=next)
1368 next=table->getNext();
1369 if (table->getShare()->getCacheKey() == identifier.getKey())
1386 table::remove_table(static_cast<table::Concurrent *>(table));
1392 prev= table->getNextPtr();
1413 for (table= session->open_tables.open_tables_; table ; table= table->getNext())
1415 if (table->getShare()->getCacheKey() == identifier.getKey())
1418 session->abortLock(table);
1454 int Session::open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags)
1456 TableList *tables= NULL;
1460 bool safe_to_ignore_table;
1462 open_tables.current_tablenr= 0;
1465 set_proc_info(
"Opening tables");
1471 for (tables= *start; tables ;tables= tables->next_global)
1473 safe_to_ignore_table=
false;
1481 if (tables->derived)
1492 identifier::Table the_table(catalog().identifier(),
1493 tables->getSchemaName(),
1494 tables->getTableName());
1495 if (not plugin::Authorization::isAuthorized(*user(), the_table))
1506 if (tables->table == NULL)
1507 tables->table= openTable(tables, &refresh, flags);
1509 if (tables->table == NULL)
1527 close_tables_for_reopen(start);
1531 if (safe_to_ignore_table)
1537 if (tables->lock_type != TL_UNLOCK)
1539 if (tables->lock_type == TL_WRITE_DEFAULT)
1540 tables->table->reginfo.lock_type= update_lock_default;
1541 else if (tables->table->getShare()->getType() == message::Table::STANDARD)
1542 tables->table->reginfo.lock_type= tables->lock_type;
1548 if (result && tables)
1554 tables->table= NULL;
1585 Table *Session::openTableLock(TableList *table_list, thr_lock_type lock_type)
1590 set_proc_info(
"Opening table");
1591 open_tables.current_tablenr= 0;
1592 while (!(table= openTable(table_list, &refresh)) && refresh) ;
1596 table_list->lock_type= lock_type;
1597 table_list->table= table;
1599 assert(open_tables.lock == 0);
1600 if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK)
1602 if (not (open_tables.lock= lockTables(&table_list->table, 1, 0)))
1640 int Session::lock_tables(TableList *tables, uint32_t count,
bool *need_reopen)
1646 *need_reopen=
false;
1651 assert(not open_tables.lock);
1654 Table** ptr=start=
new (mem) Table*[count];
1655 for (TableList* table= tables; table; table= table->next_global)
1657 if (!table->placeholder())
1658 *(ptr++)= table->table;
1660 if (not (open_tables.lock= lockTables(start, (uint32_t) (ptr - start), DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN)))
1688 Table* Session::open_temporary_table(
const identifier::Table &identifier,
bool link_in_list)
1690 assert(identifier.isTmp());
1691 table::Temporary *new_tmp_table=
new table::Temporary(identifier.getType(), identifier,
1692 identifier.getPath().c_str(),
static_cast<uint32_t
>(identifier.getPath().length()));
1696 if (new_tmp_table->getMutableShare()->open_table_def(*
this, identifier) ||
1697 new_tmp_table->getMutableShare()->open_table_from_share(
this, identifier, identifier.getTableName().c_str(),
1698 (uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX), ha_open_options, *new_tmp_table))
1701 delete new_tmp_table->getMutableShare();
1702 delete new_tmp_table;
1706 new_tmp_table->reginfo.lock_type= TL_WRITE;
1711 new_tmp_table->setNext(open_tables.temporary_tables);
1712 if (new_tmp_table->getNext())
1714 new_tmp_table->getNext()->setPrev(new_tmp_table);
1716 open_tables.temporary_tables= new_tmp_table;
1717 open_tables.temporary_tables->setPrev(0);
1719 new_tmp_table->pos_in_table_list= 0;
1721 return new_tmp_table;
1735 Field *not_found_field= (Field*) 0x1;
1736 Field *view_ref_found= (Field*) 0x2;
1738 static void update_field_dependencies(Session *session, Field *field, Table *table)
1740 if (session->mark_used_columns != MARK_COLUMNS_NONE)
1742 boost::dynamic_bitset<> *current_bitmap= NULL;
1749 table->covering_keys&= field->part_of_key;
1750 table->merge_keys|= field->part_of_key;
1752 if (session->mark_used_columns == MARK_COLUMNS_READ)
1754 current_bitmap= table->read_set;
1758 current_bitmap= table->write_set;
1762 if (current_bitmap->test(field->position()))
1764 if (session->mark_used_columns == MARK_COLUMNS_WRITE)
1765 session->dup_field= field;
1768 table->used_fields++;
1802 find_field_in_natural_join(Session *session, TableList *table_ref,
1803 const char *name, uint32_t , Item **,
1804 bool, TableList **actual_table)
1806 List<Natural_join_column>::iterator field_it(table_ref->join_columns->begin());
1807 Natural_join_column *nj_col, *curr_nj_col;
1810 assert(table_ref->is_natural_join && table_ref->join_columns);
1811 assert(*actual_table == NULL);
1813 for (nj_col= NULL, curr_nj_col= field_it++; curr_nj_col; curr_nj_col= field_it++)
1815 if (!system_charset_info->strcasecmp(curr_nj_col->name(), name))
1819 my_error(ER_NON_UNIQ_ERROR, MYF(0), name, session->where());
1822 nj_col= curr_nj_col;
1829 assert(nj_col->table_ref->table == nj_col->table_field->getTable());
1830 found_field= nj_col->table_field;
1831 update_field_dependencies(session, found_field, nj_col->table_ref->table);
1834 *actual_table= nj_col->table_ref;
1836 return(found_field);
1859 find_field_in_table(Session *session, Table *table,
const char *name, uint32_t length,
1860 bool allow_rowid, uint32_t *cached_field_index_ptr)
1862 Field **field_ptr, *field;
1863 uint32_t cached_field_index= *cached_field_index_ptr;
1866 if (cached_field_index < table->getShare()->sizeFields()
1867 && not system_charset_info->strcasecmp(table->getField(cached_field_index)->field_name, name))
1869 field_ptr= table->getFields() + cached_field_index;
1871 else if (table->getShare()->getNamedFieldSize())
1873 field_ptr= table->getMutableShare()->getNamedField(std::string(name, length));
1880 field_ptr= (table->getFields() + table->getShare()->positionFields(field_ptr));
1885 if (!(field_ptr= table->getFields()))
1887 for (; *field_ptr; ++field_ptr)
1888 if (not system_charset_info->strcasecmp((*field_ptr)->field_name, name))
1892 if (field_ptr && *field_ptr)
1894 *cached_field_index_ptr= field_ptr - table->getFields();
1900 system_charset_info->strcasecmp(name,
"_rowid") ||
1901 table->getShare()->rowid_field_offset == 0)
1903 field= table->getField(table->getShare()->rowid_field_offset-1);
1906 update_field_dependencies(session, field, table);
1954 find_field_in_table_ref(Session *session, TableList *table_list,
1955 const char *name, uint32_t length,
1956 const char *item_name,
const char *db_name,
1957 const char *table_name, Item **ref,
1959 uint32_t *cached_field_index_ptr,
1960 bool register_tree_change, TableList **actual_table)
1964 assert(table_list->alias);
1985 (!table_list->getNestedJoin()) &&
1991 table_name && table_name[0] &&
1992 (table_alias_charset->strcasecmp(table_list->alias, table_name) ||
1993 (db_name && db_name[0] && table_list->getSchemaName() && table_list->getSchemaName()[0] &&
1994 strcmp(db_name, table_list->getSchemaName()))))
1997 *actual_table= NULL;
1999 if (!table_list->getNestedJoin())
2002 assert(table_list->table);
2003 if ((fld= find_field_in_table(session, table_list->table, name, length,
2005 cached_field_index_ptr)))
2006 *actual_table= table_list;
2017 if (table_name && table_name[0])
2019 List<TableList>::iterator it(table_list->getNestedJoin()->join_list.begin());
2021 while ((table= it++))
2023 if ((fld= find_field_in_table_ref(session, table, name, length, item_name,
2024 db_name, table_name, ref,
2026 cached_field_index_ptr,
2027 register_tree_change, actual_table)))
2038 fld= find_field_in_natural_join(session, table_list, name, length, ref,
2039 register_tree_change, actual_table);
2044 if (session->mark_used_columns != MARK_COLUMNS_NONE)
2051 Field *field_to_set= NULL;
2052 if (fld == view_ref_found)
2054 Item *it= (*ref)->real_item();
2055 if (it->type() == Item::FIELD_ITEM)
2056 field_to_set= ((Item_field*)it)->field;
2059 if (session->mark_used_columns == MARK_COLUMNS_READ)
2060 it->walk(&Item::register_field_in_read_map, 1, (
unsigned char *) 0);
2067 Table *table= field_to_set->getTable();
2068 if (session->mark_used_columns == MARK_COLUMNS_READ)
2069 table->setReadSet(field_to_set->position());
2071 table->setWriteSet(field_to_set->position());
2113 find_field_in_tables(Session *session, Item_ident *item,
2114 TableList *first_table, TableList *last_table,
2115 Item **ref, find_item_error_report_type report_error,
2116 bool register_tree_change)
2119 const char *db= item->db_name;
2120 const char *table_name= item->table_name;
2121 const char *name= item->field_name;
2122 uint32_t length=(uint32_t) strlen(name);
2123 char name_buff[NAME_LEN+1];
2124 TableList *cur_table= first_table;
2125 TableList *actual_table;
2128 if (!table_name || !table_name[0])
2134 allow_rowid= table_name || (cur_table && !cur_table->next_local);
2136 if (item->cached_table)
2147 TableList *table_ref= item->cached_table;
2153 if (table_ref->table)
2154 found= find_field_in_table(session, table_ref->table, name, length,
2155 true, &(item->cached_field_index));
2157 found= find_field_in_table_ref(session, table_ref, name, length, item->name,
2159 true, &(item->cached_field_index),
2160 register_tree_change,
2169 Select_Lex *current_sel= session->lex().current_select;
2170 Select_Lex *last_select= table_ref->select_lex;
2175 if (current_sel != last_select)
2190 strncpy(name_buff, db,
sizeof(name_buff)-1);
2191 files_charset_info->casedn_str(name_buff);
2196 last_table= last_table->next_name_resolution_table;
2198 for (; cur_table != last_table ;
2199 cur_table= cur_table->next_name_resolution_table)
2201 Field *cur_field= find_field_in_table_ref(session, cur_table, name, length,
2202 item->name, db, table_name, ref,
2204 &(item->cached_field_index),
2205 register_tree_change,
2213 item->cached_table= found ? 0 : actual_table;
2215 assert(session->where());
2225 if (report_error == REPORT_ALL_ERRORS ||
2226 report_error == IGNORE_EXCEPT_NON_UNIQUE)
2227 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2228 table_name ? item->full_name() : name, session->where());
2245 if (table_name && (cur_table == first_table) &&
2246 (report_error == REPORT_ALL_ERRORS ||
2247 report_error == REPORT_EXCEPT_NON_UNIQUE))
2249 char buff[NAME_LEN*2+1];
2254 assert(strlen(db) <= NAME_LEN);
2255 assert(strlen(table_name) <= NAME_LEN);
2258 strcat(buff, table_name);
2261 my_error(ER_UNKNOWN_TABLE, MYF(0), table_name, session->where());
2265 if (report_error == REPORT_ALL_ERRORS ||
2266 report_error == REPORT_EXCEPT_NON_UNIQUE)
2267 my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(), session->where());
2269 found= not_found_field;
2309 Item **not_found_item= (Item**) 0x1;
2313 find_item_in_list(Session *session,
2314 Item *find, List<Item> &items, uint32_t *counter,
2315 find_item_error_report_type report_error,
2316 enum_resolution_type *resolution)
2318 List<Item>::iterator li(items.begin());
2319 Item **found=0, **found_unaliased= 0, *item;
2320 const char *db_name=0;
2321 const char *field_name=0;
2322 const char *table_name=0;
2323 bool found_unaliased_non_uniq= 0;
2328 bool is_ref_by_name= 0;
2329 uint32_t unaliased_counter= 0;
2331 *resolution= NOT_RESOLVED;
2333 is_ref_by_name= (find->type() == Item::FIELD_ITEM ||
2334 find->type() == Item::REF_ITEM);
2337 field_name= ((Item_ident*) find)->field_name;
2338 table_name= ((Item_ident*) find)->table_name;
2339 db_name= ((Item_ident*) find)->db_name;
2342 for (uint32_t i= 0; (item=li++); i++)
2344 if (field_name && item->real_item()->type() == Item::FIELD_ITEM)
2346 Item_ident *item_field= (Item_ident*) item;
2354 if (!item_field->name)
2375 if (item_field->field_name && item_field->table_name &&
2376 not system_charset_info->strcasecmp(item_field->field_name, field_name) &&
2377 not table_alias_charset->strcasecmp(item_field->table_name, table_name) &&
2378 (!db_name || (item_field->db_name && !strcmp(item_field->db_name, db_name))))
2380 if (found_unaliased)
2382 if ((*found_unaliased)->eq(item, 0))
2389 if (report_error != IGNORE_ERRORS)
2390 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2391 find->full_name(), session->where());
2394 found_unaliased= li.ref();
2395 unaliased_counter= i;
2396 *resolution= RESOLVED_IGNORING_ALIAS;
2403 int fname_cmp= system_charset_info->strcasecmp(item_field->field_name, field_name);
2404 if (not system_charset_info->strcasecmp(item_field->name, field_name))
2415 if ((*found)->eq(item, 0))
2417 if (report_error != IGNORE_ERRORS)
2418 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2419 find->full_name(), session->where());
2424 *resolution= fname_cmp ? RESOLVED_AGAINST_ALIAS : RESOLVED_WITH_NO_ALIAS;
2426 else if (!fname_cmp)
2434 if (found_unaliased)
2436 if ((*found_unaliased)->eq(item, 0))
2438 found_unaliased_non_uniq= 1;
2440 found_unaliased= li.ref();
2441 unaliased_counter= i;
2445 else if (!table_name)
2447 if (is_ref_by_name && find->name && item->name &&
2448 not system_charset_info->strcasecmp(item->name,find->name))
2452 *resolution= RESOLVED_AGAINST_ALIAS;
2455 else if (find->eq(item,0))
2459 *resolution= RESOLVED_IGNORING_ALIAS;
2466 if (found_unaliased_non_uniq)
2468 if (report_error != IGNORE_ERRORS)
2469 my_error(ER_NON_UNIQ_ERROR, MYF(0),
2470 find->full_name(), session->where());
2473 if (found_unaliased)
2475 found= found_unaliased;
2476 *counter= unaliased_counter;
2477 *resolution= RESOLVED_BEHIND_ALIAS;
2482 if (report_error != REPORT_EXCEPT_NOT_FOUND)
2484 if (report_error == REPORT_ALL_ERRORS)
2485 my_error(ER_BAD_FIELD_ERROR, MYF(0),
2486 find->full_name(), session->where());
2490 return (Item **) not_found_item;
2512 test_if_string_in_list(
const char *find, List<String> *str_list)
2514 List<String>::iterator str_list_it(str_list->begin());
2516 size_t find_length= strlen(find);
2517 while ((curr_str= str_list_it++))
2519 if (find_length != curr_str->length())
2521 if (not system_charset_info->strcasecmp(find, curr_str->ptr()))
2547 static void set_new_item_local_context(Session *session, Item_ident *item, TableList *table_ref)
2549 Name_resolution_context* context=
new (session->mem_root) Name_resolution_context;
2551 context->first_name_resolution_table= context->last_name_resolution_table= table_ref;
2552 item->context= context;
2588 mark_common_columns(Session *session, TableList *table_ref_1, TableList *table_ref_2,
2589 List<String> *using_fields, uint32_t *found_using_fields)
2591 Field_iterator_table_ref it_1, it_2;
2592 Natural_join_column *nj_col_1, *nj_col_2;
2593 bool first_outer_loop=
true;
2598 TableList *leaf_1= (table_ref_1->getNestedJoin() &&
2599 ! table_ref_1->is_natural_join) ?
2601 TableList *leaf_2= (table_ref_2->getNestedJoin() &&
2602 ! table_ref_2->is_natural_join) ?
2605 *found_using_fields= 0;
2607 for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
2610 const char *field_name_1;
2612 bool is_using_column_1;
2613 if (!(nj_col_1= it_1.get_or_create_column_ref(leaf_1)))
2615 field_name_1= nj_col_1->name();
2616 is_using_column_1= using_fields &&
2617 test_if_string_in_list(field_name_1, using_fields);
2627 for (it_2.set(table_ref_2); !it_2.end_of_fields(); it_2.next())
2629 Natural_join_column *cur_nj_col_2;
2630 const char *cur_field_name_2;
2631 if (!(cur_nj_col_2= it_2.get_or_create_column_ref(leaf_2)))
2633 cur_field_name_2= cur_nj_col_2->name();
2646 if (!system_charset_info->strcasecmp(field_name_1, cur_field_name_2))
2648 if (cur_nj_col_2->is_common ||
2649 (found && (!using_fields || is_using_column_1)))
2651 my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1, session->where());
2654 nj_col_2= cur_nj_col_2;
2658 if (first_outer_loop && leaf_2)
2664 leaf_2->is_join_columns_complete=
true;
2665 first_outer_loop=
false;
2675 if (nj_col_2 && (!using_fields ||is_using_column_1))
2677 Item *item_1= nj_col_1->create_item(session);
2678 Item *item_2= nj_col_2->create_item(session);
2679 Field *field_1= nj_col_1->field();
2680 Field *field_2= nj_col_2->field();
2682 if (!item_1 || !item_2)
2689 assert(item_1->type() == Item::FIELD_ITEM ||
2690 item_1->type() == Item::REF_ITEM);
2691 assert(item_2->type() == Item::FIELD_ITEM ||
2692 item_2->type() == Item::REF_ITEM);
2698 Item_ident* item_ident_1= (Item_ident*) item_1;
2699 Item_ident* item_ident_2= (Item_ident*) item_2;
2706 set_new_item_local_context(session, item_ident_1, nj_col_1->table_ref);
2707 set_new_item_local_context(session, item_ident_2, nj_col_2->table_ref);
2709 Item_func_eq* eq_cond=
new Item_func_eq(item_ident_1, item_ident_2);
2716 add_join_on((table_ref_1->outer_join & JOIN_TYPE_RIGHT ?
2717 table_ref_1 : table_ref_2),
2720 nj_col_1->is_common= nj_col_2->is_common=
true;
2724 Table *table_1= nj_col_1->table_ref->table;
2726 table_1->setReadSet(field_1->position());
2727 table_1->covering_keys&= field_1->part_of_key;
2728 table_1->merge_keys|= field_1->part_of_key;
2732 Table *table_2= nj_col_2->table_ref->table;
2734 table_2->setReadSet(field_2->position());
2735 table_2->covering_keys&= field_2->part_of_key;
2736 table_2->merge_keys|= field_2->part_of_key;
2739 if (using_fields != NULL)
2740 ++(*found_using_fields);
2744 leaf_1->is_join_columns_complete=
true;
2794 store_natural_using_join_columns(Session *session,
2795 TableList *natural_using_join,
2796 TableList *table_ref_1,
2797 TableList *table_ref_2,
2798 List<String> *using_fields,
2799 uint32_t found_using_fields)
2801 Field_iterator_table_ref it_1, it_2;
2802 Natural_join_column *nj_col_1, *nj_col_2;
2804 assert(!natural_using_join->join_columns);
2806 List<Natural_join_column>* non_join_columns=
new List<Natural_join_column>;
2807 natural_using_join->join_columns=
new List<Natural_join_column>;
2810 for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
2812 nj_col_1= it_1.get_natural_column_ref();
2813 if (nj_col_1->is_common)
2815 natural_using_join->join_columns->push_back(nj_col_1);
2817 nj_col_1->is_common=
false;
2820 non_join_columns->push_back(nj_col_1);
2828 if (using_fields && found_using_fields < using_fields->size())
2830 List<String>::iterator using_fields_it(using_fields->begin());
2831 while (String* using_field_name= using_fields_it++)
2833 const char *using_field_name_ptr= using_field_name->c_ptr();
2834 List<Natural_join_column>::iterator it(natural_using_join->join_columns->begin());
2838 Natural_join_column* common_field= it++;
2839 if (not common_field)
2841 my_error(ER_BAD_FIELD_ERROR, MYF(0), using_field_name_ptr, session->where());
2844 if (!system_charset_info->strcasecmp(common_field->name(), using_field_name_ptr))
2851 for (it_2.set(table_ref_2); !it_2.end_of_fields(); it_2.next())
2853 nj_col_2= it_2.get_natural_column_ref();
2854 if (!nj_col_2->is_common)
2855 non_join_columns->push_back(nj_col_2);
2859 nj_col_2->is_common=
false;
2863 if (non_join_columns->size() > 0)
2864 natural_using_join->join_columns->concat(non_join_columns);
2865 natural_using_join->is_join_columns_complete=
true;
2902 store_top_level_join_columns(Session *session, TableList *table_ref,
2903 TableList *left_neighbor,
2904 TableList *right_neighbor)
2907 if (table_ref->getNestedJoin())
2909 List<TableList>::iterator nested_it(table_ref->getNestedJoin()->join_list.begin());
2910 TableList *same_level_left_neighbor= nested_it++;
2911 TableList *same_level_right_neighbor= NULL;
2913 TableList *real_left_neighbor, *real_right_neighbor;
2915 while (same_level_left_neighbor)
2917 TableList *cur_table_ref= same_level_left_neighbor;
2918 same_level_left_neighbor= nested_it++;
2930 if (same_level_left_neighbor &&
2931 cur_table_ref->outer_join & JOIN_TYPE_RIGHT)
2934 assert(table_ref->getNestedJoin()->join_list.size() == 2);
2935 std::swap(same_level_left_neighbor, cur_table_ref);
2942 real_left_neighbor= (same_level_left_neighbor) ?
2943 same_level_left_neighbor : left_neighbor;
2944 real_right_neighbor= (same_level_right_neighbor) ?
2945 same_level_right_neighbor : right_neighbor;
2947 if (cur_table_ref->getNestedJoin() &&
2948 store_top_level_join_columns(session, cur_table_ref, real_left_neighbor, real_right_neighbor))
2950 same_level_right_neighbor= cur_table_ref;
2958 if (table_ref->is_natural_join)
2960 assert(table_ref->getNestedJoin() &&
2961 table_ref->getNestedJoin()->join_list.size() == 2);
2962 List<TableList>::iterator operand_it(table_ref->getNestedJoin()->join_list.begin());
2968 TableList *table_ref_2= operand_it++;
2969 TableList *table_ref_1= operand_it++;
2970 List<String> *using_fields= table_ref->join_using_fields;
2971 uint32_t found_using_fields;
2977 if (table_ref_2->outer_join & JOIN_TYPE_RIGHT)
2978 std::swap(table_ref_1, table_ref_2);
2979 if (mark_common_columns(session, table_ref_1, table_ref_2,
2980 using_fields, &found_using_fields))
2988 if (table_ref_1->outer_join & JOIN_TYPE_RIGHT)
2989 std::swap(table_ref_1, table_ref_2);
2990 if (store_natural_using_join_columns(session, table_ref, table_ref_1,
2991 table_ref_2, using_fields,
2992 found_using_fields))
3001 table_ref_1->natural_join= table_ref_2->natural_join= NULL;
3004 if (table_ref_2->outer_join &&
3005 !table_ref_1->on_expr && !table_ref_2->on_expr)
3006 table_ref_2->on_expr=
new Item_int((int64_t) 1,1);
3011 TableList *last_leaf_on_the_left;
3012 last_leaf_on_the_left= left_neighbor->last_leaf_for_name_resolution();
3013 last_leaf_on_the_left->next_name_resolution_table= table_ref;
3017 TableList *first_leaf_on_the_right;
3018 first_leaf_on_the_right= right_neighbor->first_leaf_for_name_resolution();
3019 table_ref->next_name_resolution_table= first_leaf_on_the_right;
3022 table_ref->next_name_resolution_table= NULL;
3052 static bool setup_natural_join_row_types(Session *session,
3053 List<TableList> *from_clause,
3054 Name_resolution_context *context)
3056 session->setWhere(
"from clause");
3057 if (from_clause->size() == 0)
3060 List<TableList>::iterator table_ref_it(from_clause->begin());
3061 TableList *table_ref;
3063 TableList *left_neighbor;
3065 TableList *right_neighbor= NULL;
3068 for (left_neighbor= table_ref_it++; left_neighbor ; )
3070 table_ref= left_neighbor;
3071 left_neighbor= table_ref_it++;
3072 if (store_top_level_join_columns(session, table_ref, left_neighbor, right_neighbor))
3076 TableList *first_leaf_on_the_right;
3077 first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
3078 left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
3080 right_neighbor= table_ref;
3089 assert(right_neighbor);
3090 context->first_name_resolution_table=
3091 right_neighbor->first_leaf_for_name_resolution();
3101 int setup_wild(Session *session, List<Item> &fields,
3102 List<Item> *sum_func_list,
3109 List<Item>::iterator it(fields.begin());
3111 session->lex().current_select->cur_pos_in_select_list= 0;
3112 while (wild_num && (item= it++))
3114 if (item->type() == Item::FIELD_ITEM &&
3115 ((Item_field*) item)->field_name &&
3116 ((Item_field*) item)->field_name[0] ==
'*' &&
3117 !((Item_field*) item)->field)
3119 uint32_t elem= fields.size();
3120 bool any_privileges= ((Item_field *) item)->any_privileges;
3121 Item_subselect *subsel= session->lex().current_select->master_unit()->item;
3123 subsel->substype() == Item_subselect::EXISTS_SUBS)
3130 it.replace(
new Item_int(
"Not_used", (int64_t) 1,
3131 MY_INT64_NUM_DECIMAL_DIGITS));
3133 else if (insert_fields(session, ((Item_field*) item)->context,
3134 ((Item_field*) item)->db_name,
3135 ((Item_field*) item)->table_name, &it,
3147 sum_func_list->set_size(sum_func_list->size() + fields.size() - elem);
3152 session->lex().current_select->cur_pos_in_select_list++;
3154 session->lex().current_select->cur_pos_in_select_list= UNDEF_POS;
3163 bool setup_fields(Session *session, Item **ref_pointer_array,
3164 List<Item> &fields, enum_mark_columns mark_used_columns,
3165 List<Item> *sum_func_list,
bool allow_sum_func)
3168 enum_mark_columns save_mark_used_columns= session->mark_used_columns;
3169 nesting_map save_allow_sum_func= session->lex().allow_sum_func;
3170 List<Item>::iterator it(fields.begin());
3171 bool save_is_item_list_lookup;
3173 session->mark_used_columns= mark_used_columns;
3175 session->lex().allow_sum_func|= 1 << session->lex().current_select->nest_level;
3176 session->setWhere(Session::DEFAULT_WHERE);
3177 save_is_item_list_lookup= session->lex().current_select->is_item_list_lookup;
3178 session->lex().current_select->is_item_list_lookup= 0;
3190 if (ref_pointer_array)
3192 memset(ref_pointer_array, 0,
sizeof(Item *) * fields.size());
3195 Item **ref= ref_pointer_array;
3196 session->lex().current_select->cur_pos_in_select_list= 0;
3197 while ((item= it++))
3199 if ((!item->fixed && item->fix_fields(session, it.ref())) || (item= *(it.ref()))->check_cols(1))
3201 session->lex().current_select->is_item_list_lookup= save_is_item_list_lookup;
3202 session->lex().allow_sum_func= save_allow_sum_func;
3203 session->mark_used_columns= save_mark_used_columns;
3208 if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
3210 item->split_sum_func(session, ref_pointer_array, *sum_func_list);
3211 session->used_tables|= item->used_tables();
3212 session->lex().current_select->cur_pos_in_select_list++;
3214 session->lex().current_select->is_item_list_lookup= save_is_item_list_lookup;
3215 session->lex().current_select->cur_pos_in_select_list= UNDEF_POS;
3217 session->lex().allow_sum_func= save_allow_sum_func;
3218 session->mark_used_columns= save_mark_used_columns;
3219 return(test(session->is_error()));
3234 static TableList **make_leaves_list(TableList **list, TableList *tables)
3236 for (TableList *table= tables; table; table= table->next_local)
3274 bool setup_tables(Session *session, Name_resolution_context *context,
3275 List<TableList> *from_clause, TableList *tables,
3276 TableList **leaves,
bool select_insert)
3278 assert((select_insert && !tables->next_name_resolution_table) || !tables ||
3279 (context->table_list && context->first_name_resolution_table));
3284 TableList *first_select_table= select_insert ? tables->next_local : NULL;
3287 make_leaves_list(leaves, tables);
3289 uint32_t tablenr= 0;
3290 for (TableList* table_list= *leaves; table_list; table_list= table_list->next_leaf, tablenr++)
3292 Table *table= table_list->table;
3293 table->pos_in_table_list= table_list;
3294 if (first_select_table &&
3295 table_list->top_table() == first_select_table)
3298 first_select_table= 0;
3301 table->setup_table_map(table_list, tablenr);
3302 if (table_list->process_index_hints(table))
3305 if (tablenr > MAX_TABLES)
3307 my_error(ER_TOO_MANY_TABLES,MYF(0),MAX_TABLES);
3312 if (setup_natural_join_row_types(session, from_clause, context))
3342 bool setup_tables_and_check_access(Session *session,
3343 Name_resolution_context *context,
3344 List<TableList> *from_clause,
3349 TableList *leaves_tmp= NULL;
3351 if (setup_tables(session, context, from_clause, tables, &leaves_tmp, select_insert))
3355 *leaves= leaves_tmp;
3380 insert_fields(Session *session, Name_resolution_context *context,
const char *db_name,
3381 const char *table_name, List<Item>::iterator *it,
3384 Field_iterator_table_ref field_iterator;
3386 char name_buff[NAME_LEN+1];
3395 strncpy(name_buff, db_name,
sizeof(name_buff)-1);
3396 files_charset_info->casedn_str(name_buff);
3407 for (TableList *tables= (table_name ? context->table_list :
3408 context->first_name_resolution_table);
3410 tables= (table_name ? tables->next_local :
3411 tables->next_name_resolution_table)
3415 Table *table= tables->table;
3417 assert(tables->is_leaf_for_name_resolution());
3419 if ((table_name && table_alias_charset->strcasecmp(table_name, tables->alias)) ||
3420 (db_name && system_charset_info->strcasecmp(tables->getSchemaName(),db_name)))
3428 session->used_tables|= table->map;
3436 field_iterator.set(tables);
3438 for (; !field_iterator.end_of_fields(); field_iterator.next())
3440 Item *item= field_iterator.create_item(session);
3452 if ((field= field_iterator.field()))
3455 field->getTable()->setReadSet(field->position());
3458 table->covering_keys&= field->part_of_key;
3459 table->merge_keys|= field->part_of_key;
3461 if (tables->is_natural_join)
3468 Natural_join_column *nj_col;
3469 if (!(nj_col= field_iterator.get_natural_column_ref()))
3471 assert(nj_col->table_field);
3472 field_table= nj_col->table_ref->table;
3475 session->used_tables|= field_table->map;
3476 field_table->covering_keys&= field->part_of_key;
3477 field_table->merge_keys|= field->part_of_key;
3478 field_table->used_fields++;
3484 session->used_tables|= item->used_tables();
3487 session->lex().current_select->cur_pos_in_select_list++;
3496 table->used_fields= table->getShare()->sizeFields();
3508 my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
3512 my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name);
3537 int Session::setup_conds(TableList *leaves, COND **conds)
3539 Session *session=
this;
3540 Select_Lex *select_lex= session->lex().current_select;
3541 TableList *table= NULL;
3542 void *save_session_marker= session->session_marker;
3551 bool save_is_item_list_lookup= select_lex->is_item_list_lookup;
3552 select_lex->is_item_list_lookup= 0;
3554 session->mark_used_columns= MARK_COLUMNS_READ;
3555 select_lex->cond_count= 0;
3556 select_lex->between_count= 0;
3557 select_lex->max_equal_elems= 0;
3559 session->session_marker= (
void*)1;
3562 session->setWhere(
"where clause");
3563 if ((!(*conds)->fixed && (*conds)->fix_fields(session, conds)) ||
3564 (*conds)->check_cols(1))
3567 session->session_marker= save_session_marker;
3573 for (table= leaves; table; table= table->next_leaf)
3575 TableList *embedded;
3576 TableList *embedding= table;
3579 embedded= embedding;
3580 if (embedded->on_expr)
3583 session->session_marker= (
void*)embedded;
3584 session->setWhere(
"on clause");
3585 if ((!embedded->on_expr->fixed && embedded->on_expr->fix_fields(session, &embedded->on_expr)) ||
3586 embedded->on_expr->check_cols(1))
3588 select_lex->cond_count++;
3590 embedding= embedded->getEmbedding();
3593 &embedding->getNestedJoin()->join_list.front() == embedded);
3596 session->session_marker= save_session_marker;
3598 session->lex().current_select->is_item_list_lookup= save_is_item_list_lookup;
3599 return(test(session->is_error()));
3602 select_lex->is_item_list_lookup= save_is_item_list_lookup;
3634 fill_record(Session *session, List<Item> &fields, List<Item> &values,
bool ignore_errors)
3636 List<Item>::iterator f(fields.begin());
3637 List<Item>::iterator v(values.begin());
3652 field=
static_cast<Item_field *
>(f++);
3653 table= field->field->getTable();
3654 table->auto_increment_field_not_null=
false;
3658 while ((field= static_cast<Item_field *>(f++)))
3662 Field *rfield= field->field;
3663 table= rfield->getTable();
3665 if (rfield == table->next_number_field)
3666 table->auto_increment_field_not_null=
true;
3667 if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
3669 my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
3671 table->auto_increment_field_not_null=
false;
3677 return session->is_error();
3700 bool fill_record(Session *session, Field **ptr, List<Item> &values,
bool)
3702 List<Item>::iterator v(values.begin());
3717 table= (*ptr)->getTable();
3718 table->auto_increment_field_not_null=
false;
3721 while ((field = *ptr++) && ! session->is_error())
3724 table= field->getTable();
3726 if (field == table->next_number_field)
3728 table->auto_increment_field_not_null=
true;
3731 if (value->save_in_field(field, 0) < 0)
3734 table->auto_increment_field_not_null=
false;
3740 return(session->is_error());
3744 void drizzle_rm_tmp_tables()
3746 assert(drizzle_tmpdir.size());
3747 Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
3748 session->thread_stack= (
char*) session.get();
3749 session->storeGlobals();
3750 plugin::StorageEngine::removeLostTemporaryTables(*session, drizzle_tmpdir.c_str());
3759 pthread_kill(signal_thread, SIGTERM);
3760 shutdown_in_progress=
true;
void removeLock(Table *table)
void broadcast_refresh(void)
Table * table
opened table
TableList * find_underlying_table(Table *table)
Defines the interface to the CachedDirectory class.
field::Epoch * timestamp_field
void mark_select_range_as_dependent(Session *session, Select_Lex *last_select, Select_Lex *current_sel, Field *found_field, Item *found_item, Item_ident *resolved_item)
virtual timestamp_auto_set_type get_auto_set_type() const