303
304
Get a table share. If it didn't exist, try creating it from engine
305
306
For arguments and return values, see get_table_from_share()
309
*get_table_share_with_create(Session *session, TableList *table_list,
310
char *key, uint32_t key_length,
311
uint32_t db_flags, int *error)
308
static TableShare *get_table_share_with_create(Session *session,
309
TableList *table_list,
313
315
TableShare *share;
525
514
for (table= open_list ; table ; table=table->next)
527
516
if (!strcmp(table->table, share->table_name.str) &&
528
!strcmp(table->db, share->db.str))
517
!strcmp(table->db, share->db.str))
532
if (entry->locked_by_name)
521
if (entry->locked_by_name)
626
611
@remark Session can be NULL, but then wait_for_refresh must be false
627
612
and tables must be NULL.
630
bool close_cached_tables(Session *session, TableList *tables, bool have_lock,
631
bool wait_for_refresh, bool wait_for_placeholders)
614
bool close_cached_tables(Session *session,
617
bool wait_for_refresh,
618
bool wait_for_placeholders)
634
621
assert(session || (!wait_for_refresh && !tables));
750
737
are employed by CREATE TABLE as in this case table simply does not
753
if (table->needs_reopen_or_name_lock() && (table->db_stat ||
754
(table->open_placeholder && wait_for_placeholders)))
757
pthread_cond_wait(&COND_refresh,&LOCK_open);
740
if (table->needs_reopen_or_name_lock() && (table->db_stat ||
741
(table->open_placeholder && wait_for_placeholders)))
744
pthread_cond_wait(&COND_refresh,&LOCK_open);
796
782
Close all tables which match specified connection string or
797
783
if specified string is NULL, then any table with a connection string.
800
bool close_cached_connection_tables(Session *session, bool if_wait_for_refresh,
801
LEX_STRING *connection, bool have_lock)
785
bool close_cached_connection_tables(Session *session,
786
bool if_wait_for_refresh,
787
LEX_STRING *connection,
804
791
TableList tmp, *tables= NULL;
1497
1460
Currently, however, this function is never called for a
1498
1461
table that was locked with LOCK TABLES.
1501
void drop_open_table(Session *session, Table *table, const char *db_name,
1463
void drop_open_table(Session *session, Table *table,
1464
const char *db_name,
1502
1465
const char *table_name)
1504
1467
if (table->s->tmp_table)
1754
1709
@retval true Error occured (OOM)
1755
1710
@retval false Success. 'table' parameter set according to above rules.
1758
bool lock_table_name_if_not_cached(Session *session, const char *db,
1759
const char *table_name, Table **table)
1712
bool lock_table_name_if_not_cached(Session *session,
1714
const char *table_name,
1761
1717
char key[MAX_DBKEY_LENGTH];
1762
1718
char *key_pos= key;
2683
2625
next=table->next;
2684
2626
if (!strcmp(table->s->table_name.str, table_name) &&
2685
!strcmp(table->s->db.str, db))
2627
!strcmp(table->s->db.str, db))
2687
2629
mysql_lock_remove(session, session->locked_tables, table, true);
2826
2769
if (!entry->s || !entry->s->crashed)
2828
// Code below is for repairing a crashed file
2829
if ((error= lock_table_name(session, table_list, true)))
2833
if (wait_for_locked_table_names(session, table_list))
2835
unlock_table_name(table_list);
2839
pthread_mutex_unlock(&LOCK_open);
2840
session->clear_error(); // Clear error message
2842
if (open_table_from_share(session, share, alias,
2843
(uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
2847
ha_open_options | HA_OPEN_FOR_REPAIR,
2848
entry, OTM_OPEN) || ! entry->file ||
2849
(entry->file->is_crashed() && entry->file->ha_check_and_repair(session)))
2851
/* Give right error message */
2852
session->clear_error();
2853
my_error(ER_NOT_KEYFILE, MYF(0), share->table_name.str, my_errno);
2854
errmsg_printf(ERRMSG_LVL_ERROR, _("Couldn't repair table: %s.%s"), share->db.str,
2855
share->table_name.str);
2857
entry->closefrm(false);
2861
session->clear_error(); // Clear error message
2862
pthread_mutex_lock(&LOCK_open);
2863
unlock_table_name(table_list);
2771
// Code below is for repairing a crashed file
2772
if ((error= lock_table_name(session, table_list, true)))
2776
if (wait_for_locked_table_names(session, table_list))
2778
unlock_table_name(table_list);
2782
pthread_mutex_unlock(&LOCK_open);
2783
session->clear_error(); // Clear error message
2785
if (open_table_from_share(session, share, alias,
2786
(uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
2790
ha_open_options | HA_OPEN_FOR_REPAIR,
2791
entry, OTM_OPEN) || ! entry->file ||
2792
(entry->file->is_crashed() && entry->file->ha_check_and_repair(session)))
2794
/* Give right error message */
2795
session->clear_error();
2796
my_error(ER_NOT_KEYFILE, MYF(0), share->table_name.str, my_errno);
2797
errmsg_printf(ERRMSG_LVL_ERROR, _("Couldn't repair table: %s.%s"), share->db.str,
2798
share->table_name.str);
2800
entry->closefrm(false);
2804
session->clear_error(); // Clear error message
2805
pthread_mutex_lock(&LOCK_open);
2806
unlock_table_name(table_list);
2871
2814
If we are here, there was no fatal error (but error may be still
3114
3051
neither call decide_logging_format() nor handle some other logging
3115
3052
and locking issues because it does not call lock_tables().
3118
Table *open_n_lock_single_table(Session *session, TableList *table_l,
3054
Table *open_n_lock_single_table(Session *session,
3119
3056
thr_lock_type lock_type)
3121
3058
TableList *save_next_global;
3182
3119
if (session->locked_tables)
3184
3121
if (check_lock_and_start_stmt(session, table, lock_type))
3189
3126
assert(session->lock == 0); // You must lock everything at once
3190
3127
if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK)
3191
if (! (session->lock= mysql_lock_tables(session, &table_list->table, 1,
3192
lock_flags, &refresh)))
3128
if (! (session->lock= mysql_lock_tables(session, &table_list->table, 1, lock_flags, &refresh)))
3415
Table *open_temporary_table(Session *session, const char *path, const char *db,
3416
const char *table_name, bool link_in_list,
3342
Table *open_temporary_table(Session *session,
3345
const char *table_name,
3417
3347
open_table_mode open_mode)
3419
3349
Table *tmp_table;
3587
3514
WRONG_GRANT if no access rights to the found field
3588
3515
# Pointer to the found Field
3592
find_field_in_natural_join(Session *session, TableList *table_ref,
3593
const char *name, uint32_t , Item **,
3594
bool, TableList **actual_table)
3517
static Field *find_field_in_natural_join(Session *session,
3518
TableList *table_ref,
3523
TableList **actual_table)
3596
List_iterator_fast<Natural_join_column>
3597
field_it(*(table_ref->join_columns));
3525
List_iterator_fast<Natural_join_column> field_it(*(table_ref->join_columns));
3598
3526
Natural_join_column *nj_col, *curr_nj_col;
3599
3527
Field *found_field;
3646
3573
0 field is not found
3647
3574
# pointer to field
3651
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
3652
bool allow_rowid, uint32_t *cached_field_index_ptr)
3576
Field *find_field_in_table(Session *session,
3581
uint32_t *cached_field_index_ptr)
3654
3583
Field **field_ptr, *field;
3655
3584
uint32_t cached_field_index= *cached_field_index_ptr;
3742
3670
view_ref_found found value in VIEW (real result is in *ref)
3743
3671
# pointer to field
3747
find_field_in_table_ref(Session *session, TableList *table_list,
3748
const char *name, uint32_t length,
3749
const char *item_name, const char *db_name,
3750
const char *table_name, Item **ref,
3751
bool check_privileges, bool allow_rowid,
3752
uint32_t *cached_field_index_ptr,
3753
bool register_tree_change, TableList **actual_table)
3673
Field *find_field_in_table_ref(Session *session,
3674
TableList *table_list,
3677
const char *item_name,
3678
const char *db_name,
3679
const char *table_name,
3681
bool check_privileges,
3683
uint32_t *cached_field_index_ptr,
3684
bool register_tree_change,
3685
TableList **actual_table)
3755
3687
Field *fld= NULL;
3949
3878
view_ref_found View field is found, item passed through ref parameter
3950
3879
found field If a item was resolved to some field
3954
find_field_in_tables(Session *session, Item_ident *item,
3955
TableList *first_table, TableList *last_table,
3956
Item **ref, find_item_error_report_type report_error,
3957
bool check_privileges, bool register_tree_change)
3881
Field *find_field_in_tables(Session *session,
3883
TableList *first_table,
3884
TableList *last_table,
3886
find_item_error_report_type report_error,
3887
bool check_privileges,
3888
bool register_tree_change)
3959
3890
Field *found=0;
3960
3891
const char *db= item->db_name;
4178
4108
/* Special Item pointer to serve as a return value from find_item_in_list(). */
4179
4109
Item **not_found_item= (Item**) 0x1;
4183
find_item_in_list(Item *find, List<Item> &items, uint32_t *counter,
4184
find_item_error_report_type report_error,
4185
enum_resolution_type *resolution)
4111
Item **find_item_in_list(Item *find,
4114
find_item_error_report_type report_error,
4115
enum_resolution_type *resolution)
4187
4117
List_iterator<Item> li(items);
4188
4118
Item **found=0, **found_unaliased= 0, *item;
4215
4145
Item_ident *item_field= (Item_ident*) item;
4218
In case of group_concat() with ORDER BY condition in the QUERY
4219
item_field can be field of temporary table without item name
4220
(if this field created from expression argument of group_concat()),
4221
=> we have to check presence of name before compare
4148
In case of group_concat() with ORDER BY condition in the QUERY
4149
item_field can be field of temporary table without item name
4150
(if this field created from expression argument of group_concat()),
4151
=> we have to check presence of name before compare
4223
4153
if (!item_field->name)
4238
4168
case sensitive. In cases where they are not case sensitive, they
4239
4169
are always in lower case.
4241
item_field->field_name and item_field->table_name can be 0x0 if
4242
item is not fix_field()'ed yet.
4171
item_field->field_name and item_field->table_name can be 0x0 if
4172
item is not fix_field()'ed yet.
4244
4174
if (item_field->field_name && item_field->table_name &&
4245
!my_strcasecmp(system_charset_info, item_field->field_name,
4247
!my_strcasecmp(table_alias_charset, item_field->table_name,
4175
!my_strcasecmp(system_charset_info, item_field->field_name, field_name) &&
4176
!my_strcasecmp(table_alias_charset, item_field->table_name, table_name) &&
4249
4177
(!db_name || (item_field->db_name &&
4250
4178
!strcmp(item_field->db_name, db_name))))
4259
4187
unaliased names only and will have duplicate error anyway.
4261
4189
if (report_error != IGNORE_ERRORS)
4262
my_error(ER_NON_UNIQ_ERROR, MYF(0),
4263
find->full_name(), current_session->where);
4190
my_error(ER_NON_UNIQ_ERROR, MYF(0), find->full_name(), current_session->where);
4264
4191
return (Item**) 0;
4266
4193
found_unaliased= li.ref();
4464
4384
true error when some common column is non-unique, or out of memory
4469
mark_common_columns(Session *session, TableList *table_ref_1, TableList *table_ref_2,
4470
List<String> *using_fields, uint32_t *found_using_fields)
4387
static bool mark_common_columns(Session *session,
4388
TableList *table_ref_1,
4389
TableList *table_ref_2,
4390
List<String> *using_fields,
4391
uint32_t *found_using_fields)
4472
4393
Field_iterator_table_ref it_1, it_2;
4473
4394
Natural_join_column *nj_col_1, *nj_col_2;
4678
4597
true error: Some common column is ambiguous
4683
store_natural_using_join_columns(Session *,
4684
TableList *natural_using_join,
4685
TableList *table_ref_1,
4686
TableList *table_ref_2,
4687
List<String> *using_fields,
4688
uint32_t found_using_fields)
4600
static bool store_natural_using_join_columns(Session *,
4601
TableList *natural_using_join,
4602
TableList *table_ref_1,
4603
TableList *table_ref_2,
4604
List<String> *using_fields,
4605
uint32_t found_using_fields)
4690
4607
Field_iterator_table_ref it_1, it_2;
4691
4608
Natural_join_column *nj_col_1, *nj_col_2;
4802
store_top_level_join_columns(Session *session, TableList *table_ref,
4803
TableList *left_neighbor,
4804
TableList *right_neighbor)
4716
static bool store_top_level_join_columns(Session *session,
4717
TableList *table_ref,
4718
TableList *left_neighbor,
4719
TableList *right_neighbor)
4806
4721
bool result= true;
5005
4919
** Expand all '*' in given fields
5006
4920
****************************************************************************/
5008
int setup_wild(Session *session, List<Item> &fields,
4922
int setup_wild(Session *session,
5009
4924
List<Item> *sum_func_list,
5010
4925
uint32_t wild_num)
5021
4936
if (item->type() == Item::FIELD_ITEM &&
5022
4937
((Item_field*) item)->field_name &&
5023
((Item_field*) item)->field_name[0] == '*' &&
5024
!((Item_field*) item)->field)
4938
((Item_field*) item)->field_name[0] == '*' &&
4939
!((Item_field*) item)->field)
5026
4941
uint32_t elem= fields.elements;
5027
4942
bool any_privileges= ((Item_field *) item)->any_privileges;
5042
4957
((Item_field*) item)->table_name, &it,
5043
4958
any_privileges))
5047
4962
if (sum_func_list)
5050
sum_func_list is a list that has the fields list as a tail.
5051
Because of this we have to update the element count also for this
5052
list after expanding the '*' entry.
5054
sum_func_list->elements+= fields.elements - elem;
4965
sum_func_list is a list that has the fields list as a tail.
4966
Because of this we have to update the element count also for this
4967
list after expanding the '*' entry.
4969
sum_func_list->elements+= fields.elements - elem;
5066
4981
** Check that all given fields exists and fill struct with current data
5067
4982
****************************************************************************/
5069
bool setup_fields(Session *session, Item **ref_pointer_array,
5070
List<Item> &fields, enum_mark_columns mark_used_columns,
5071
List<Item> *sum_func_list, bool allow_sum_func)
4984
bool setup_fields(Session *session,
4985
Item **ref_pointer_array,
4987
enum_mark_columns mark_used_columns,
4988
List<Item> *sum_func_list,
4989
bool allow_sum_func)
5073
4991
register Item *item;
5074
4992
enum_mark_columns save_mark_used_columns= session->mark_used_columns;
5175
5091
false ok; In this case *map will includes the chosen index
5179
bool setup_tables(Session *session, Name_resolution_context *context,
5180
List<TableList> *from_clause, TableList *tables,
5181
TableList **leaves, bool select_insert)
5094
bool setup_tables(Session *session,
5095
Name_resolution_context *context,
5096
List<TableList> *from_clause,
5183
5101
uint32_t tablenr= 0;
5286
5202
0 ok; In this case *map will includes the choosed index
5290
bool get_key_map_from_key_list(key_map *map, Table *table,
5291
List<String> *index_list)
5205
bool get_key_map_from_key_list(key_map *map, Table *table, List<String> *index_list)
5293
5207
List_iterator_fast<String> it(*index_list);
5330
5243
0 ok 'it' is updated to point at last inserted
5331
5244
1 error. Error message is generated but not sent to client
5335
insert_fields(Session *session, Name_resolution_context *context, const char *db_name,
5336
const char *table_name, List_iterator<Item> *it,
5246
bool insert_fields(Session *session,
5247
Name_resolution_context *context,
5248
const char *db_name,
5249
const char *table_name,
5250
List_iterator<Item> *it,
5339
5253
Field_iterator_table_ref field_iterator;
5531
5443
session->session_marker= (void*)embedded;
5532
5444
session->where="on clause";
5533
5445
if ((!embedded->on_expr->fixed && embedded->on_expr->fix_fields(session, &embedded->on_expr)) ||
5534
embedded->on_expr->check_cols(1))
5446
embedded->on_expr->check_cols(1))
5536
5448
select_lex->cond_count++;
5538
5450
embedding= embedded->embedding;
5874
5771
can access the table until close_thread_tables() is called.
5875
5772
1 Table is in use by another thread
5878
bool remove_table_from_cache(Session *session, const char *db, const char *table_name,
5774
bool remove_table_from_cache(Session *session,
5776
const char *table_name,
5879
5777
uint32_t flags)
5881
5779
char key[MAX_DBKEY_LENGTH];
5923
Now we must abort all tables locks used by this thread
5924
as the thread may be waiting to get a lock for another table.
5821
Now we must abort all tables locks used by this thread
5822
as the thread may be waiting to get a lock for another table.
5925
5823
Note that we need to hold LOCK_open while going through the
5926
5824
list. So that the other thread cannot change it. The other
5927
5825
thread must also hold LOCK_open whenever changing the
5929
5827
closed and before the parent is closed would be fatal.
5931
5829
for (Table *session_table= in_use->open_tables;
5933
session_table= session_table->next)
5831
session_table= session_table->next)
5935
5833
/* Do not handle locks of MERGE children. */
5936
if (session_table->db_stat) // If table is open
5937
signalled|= mysql_lock_abort_for_thread(session, session_table);
5834
if (session_table->db_stat) // If table is open
5835
signalled|= mysql_lock_abort_for_thread(session, session_table);