#include "procedure.h"#include <myisam.h>Include dependency graph for sql_select.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
| typedef struct st_cache_field CACHE_FIELD |
| typedef struct st_join_cache JOIN_CACHE |
| typedef struct st_join_table JOIN_TAB |
| typedef enum_nested_loop_state(*) Next_select_func(JOIN *, struct st_join_table *, bool) |
Definition at line 102 of file sql_select.h.
| typedef struct st_position POSITION |
| typedef int(*) Read_record_func(struct st_join_table *tab) |
Definition at line 103 of file sql_select.h.
| typedef struct st_select_check SELECT_CHECK |
| typedef struct st_table_ref TABLE_REF |
| NESTED_LOOP_KILLED | |
| NESTED_LOOP_ERROR | |
| NESTED_LOOP_OK | |
| NESTED_LOOP_NO_MORE_ROWS | |
| NESTED_LOOP_QUERY_LIMIT | |
| NESTED_LOOP_CURSOR_LIMIT |
Definition at line 94 of file sql_select.h.
00095 { 00096 NESTED_LOOP_KILLED= -2, NESTED_LOOP_ERROR= -1, 00097 NESTED_LOOP_OK= 0, NESTED_LOOP_NO_MORE_ROWS= 1, 00098 NESTED_LOOP_QUERY_LIMIT= 3, NESTED_LOOP_CURSOR_LIMIT= 4 00099 };
| enum join_type |
| JT_UNKNOWN | |
| JT_SYSTEM | |
| JT_CONST | |
| JT_EQ_REF | |
| JT_REF | |
| JT_MAYBE_REF | |
| JT_ALL | |
| JT_RANGE | |
| JT_NEXT | |
| JT_FT | |
| JT_REF_OR_NULL | |
| JT_UNIQUE_SUBQUERY | |
| JT_INDEX_SUBQUERY | |
| JT_INDEX_MERGE |
Definition at line 88 of file sql_select.h.
00088 { JT_UNKNOWN,JT_SYSTEM,JT_CONST,JT_EQ_REF,JT_REF,JT_MAYBE_REF, 00089 JT_ALL, JT_RANGE, JT_NEXT, JT_FT, JT_REF_OR_NULL, 00090 JT_UNIQUE_SUBQUERY, JT_INDEX_SUBQUERY, JT_INDEX_MERGE};
| void copy_fields | ( | TMP_TABLE_PARAM * | param | ) |
Definition at line 13352 of file sql_select.cc.
References Copy_field::do_copy.
Referenced by Item_sum_count_distinct::add(), Item_func_group_concat::add(), JOIN::clear(), end_send_group(), end_unique_update(), end_update(), end_write(), end_write_group(), and QUICK_GROUP_MIN_MAX_SELECT::get_next().
13353 { 13354 Copy_field *ptr=param->copy_field; 13355 Copy_field *end=param->copy_field_end; 13356 13357 for (; ptr != end; ptr++) 13358 (*ptr->do_copy)(ptr); 13359 13360 List_iterator_fast<Item> it(param->copy_funcs); 13361 Item_copy_string *item; 13362 while ((item = (Item_copy_string*) it++)) 13363 item->copy(); 13364 }
Here is the caller graph for this function:

| void copy_funcs | ( | Item ** | func_ptr | ) |
Definition at line 13676 of file sql_select.cc.
References func.
Referenced by Item_sum_count_distinct::add(), Item_func_group_concat::add(), end_unique_update(), end_update(), end_write(), and end_write_group().
13677 { 13678 Item *func; 13679 for (; (func = *func_ptr) ; func_ptr++) 13680 func->save_in_result_field(1); 13681 }
Here is the caller graph for this function:

Definition at line 12974 of file sql_select.cc.
References Item::const_item(), Item::FIELD_ITEM, Item::real_item(), Item::SUM_FUNC_ITEM, Item::type(), and Item::with_sum_func.
Referenced by JOIN::exec(), JOIN::prepare(), Item_sum_count_distinct::setup(), Item_func_group_concat::setup(), and Item_in_subselect::single_value_transformer().
12976 { 12977 List_iterator<Item> li(fields); 12978 Item *field; 12979 12980 param->field_count=param->sum_func_count=param->func_count= 12981 param->hidden_field_count=0; 12982 param->quick_group=1; 12983 while ((field=li++)) 12984 { 12985 Item::Type type=field->real_item()->type(); 12986 if (type == Item::FIELD_ITEM) 12987 param->field_count++; 12988 else if (type == Item::SUM_FUNC_ITEM) 12989 { 12990 if (! field->const_item()) 12991 { 12992 Item_sum *sum_item=(Item_sum*) field->real_item(); 12993 if (!sum_item->quick_group) 12994 param->quick_group=0; // UDF SUM function 12995 param->sum_func_count++; 12996 12997 for (uint i=0 ; i < sum_item->arg_count ; i++) 12998 { 12999 if (sum_item->args[0]->real_item()->type() == Item::FIELD_ITEM) 13000 param->field_count++; 13001 else 13002 param->func_count++; 13003 } 13004 } 13005 } 13006 else 13007 { 13008 param->func_count++; 13009 if (reset_with_sum_func) 13010 field->with_sum_func=0; 13011 } 13012 } 13013 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 12575 of file sql_select.cc.
References CHECK_FIELD_IGNORE, mySTL::copy(), dbug_tmp_restore_column_map(), dbug_tmp_use_all_columns(), st_table_ref::key_copy, and st_table::write_set.
Referenced by cmp_buffer_with_ref(), get_quick_select_for_ref(), join_ft_read_first(), join_read_always_key(), join_read_const(), and join_read_last_key().
12576 { 12577 enum enum_check_fields save_count_cuted_fields= thd->count_cuted_fields; 12578 thd->count_cuted_fields= CHECK_FIELD_IGNORE; 12579 my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set); 12580 bool result= 0; 12581 12582 for (store_key **copy=ref->key_copy ; *copy ; copy++) 12583 { 12584 if ((*copy)->copy() & 1) 12585 { 12586 result= 1; 12587 break; 12588 } 12589 } 12590 thd->count_cuted_fields= save_count_cuted_fields; 12591 dbug_tmp_restore_column_map(table->write_set, old_map); 12592 return result; 12593 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool create_myisam_from_heap | ( | THD * | thd, | |
| TABLE * | table, | |||
| TMP_TABLE_PARAM * | param, | |||
| int | error, | |||
| bool | ignore_last_dupp_error | |||
| ) |
Definition at line 9437 of file sql_select.cc.
References handler::change_table_ptr(), handler::close(), create_myisam_tmp_table(), st_table_share::db_type, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, handler::delete_table(), handler::disable_indexes(), err, handler::extra(), st_table::file, get_new_handler(), HA_CHECK_DUP, HA_ERR_RECORD_FILE_FULL, HA_EXTRA_NO_ROWS, HA_EXTRA_WRITE_CACHE, handler::ha_index_or_rnd_end(), HA_KEY_SWITCH_ALL, handler::ha_rnd_end(), handler::ha_rnd_init(), handler::ha_start_bulk_insert(), HA_STATUS_VARIABLE, heap_hton, handler::indexes_are_disabled(), handler::info(), handler::is_fatal_error(), st_table::mem_root, MYF, myisam_hton, st_table::no_rows, open_tmp_table(), handler::print_error(), st_table::record, ha_statistics::records, handler::rnd_next(), st_table::s, handler::stats, LEX_STRING::str, strcmp(), st_table_share::table_name, st_table::use_all_columns(), and handler::write_row().
Referenced by end_update(), end_write(), end_write_group(), JOIN::rollup_write_data(), and schema_table_store_record().
09439 { 09440 TABLE new_table; 09441 TABLE_SHARE share; 09442 const char *save_proc_info; 09443 int write_err; 09444 DBUG_ENTER("create_myisam_from_heap"); 09445 09446 if (table->s->db_type != &heap_hton || 09447 error != HA_ERR_RECORD_FILE_FULL) 09448 { 09449 table->file->print_error(error,MYF(0)); 09450 DBUG_RETURN(1); 09451 } 09452 new_table= *table; 09453 share= *table->s; 09454 new_table.s= &share; 09455 new_table.s->db_type= &myisam_hton; 09456 if (!(new_table.file= get_new_handler(&share, &new_table.mem_root, 09457 &myisam_hton))) 09458 DBUG_RETURN(1); // End of memory 09459 09460 save_proc_info=thd->proc_info; 09461 thd->proc_info="converting HEAP to MyISAM"; 09462 09463 if (create_myisam_tmp_table(&new_table, param, 09464 thd->lex->select_lex.options | thd->options)) 09465 goto err2; 09466 if (open_tmp_table(&new_table)) 09467 goto err1; 09468 if (table->file->indexes_are_disabled()) 09469 new_table.file->disable_indexes(HA_KEY_SWITCH_ALL); 09470 table->file->ha_index_or_rnd_end(); 09471 table->file->ha_rnd_init(1); 09472 if (table->no_rows) 09473 { 09474 new_table.file->extra(HA_EXTRA_NO_ROWS); 09475 new_table.no_rows=1; 09476 } 09477 09478 #ifdef TO_BE_DONE_LATER_IN_4_1 09479 /* 09480 To use start_bulk_insert() (which is new in 4.1) we need to find 09481 all places where a corresponding end_bulk_insert() should be put. 09482 */ 09483 table->file->info(HA_STATUS_VARIABLE); /* update table->file->stats.records */ 09484 new_table.file->ha_start_bulk_insert(table->file->stats.records); 09485 #else 09486 /* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */ 09487 new_table.file->extra(HA_EXTRA_WRITE_CACHE); 09488 #endif 09489 09490 /* 09491 copy all old rows from heap table to MyISAM table 09492 This is the only code that uses record[1] to read/write but this 09493 is safe as this is a temporary MyISAM table without timestamp/autoincrement 09494 or partitioning. 09495 */ 09496 while (!table->file->rnd_next(new_table.record[1])) 09497 { 09498 if ((write_err= new_table.file->write_row(new_table.record[1]))) 09499 goto err; 09500 } 09501 /* copy row that filled HEAP table */ 09502 if ((write_err=new_table.file->write_row(table->record[0]))) 09503 { 09504 if (new_table.file->is_fatal_error(write_err, HA_CHECK_DUP) || 09505 !ignore_last_dupp_key_error) 09506 goto err; 09507 } 09508 09509 /* remove heap table and change to use myisam table */ 09510 (void) table->file->ha_rnd_end(); 09511 (void) table->file->close(); 09512 (void) table->file->delete_table(table->s->table_name.str); 09513 delete table->file; 09514 table->file=0; 09515 new_table.s= table->s; // Keep old share 09516 *table= new_table; 09517 *table->s= share; 09518 table->file->change_table_ptr(table, table->s); 09519 table->use_all_columns(); 09520 if (save_proc_info) 09521 thd->proc_info= (!strcmp(save_proc_info,"Copying to tmp table") ? 09522 "Copying to tmp table on disk" : save_proc_info); 09523 DBUG_RETURN(0); 09524 09525 err: 09526 DBUG_PRINT("error",("Got error: %d",write_err)); 09527 table->file->print_error(error,MYF(0)); // Give table is full error 09528 (void) table->file->ha_rnd_end(); 09529 (void) new_table.file->close(); 09530 err1: 09531 new_table.file->delete_table(new_table.s->table_name.str); 09532 err2: 09533 delete new_table.file; 09534 thd->proc_info=save_proc_info; 09535 DBUG_RETURN(1); 09536 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Field* create_tmp_field_from_field | ( | THD * | thd, | |
| Field * | org_field, | |||
| const char * | name, | |||
| TABLE * | table, | |||
| Item_field * | item, | |||
| uint | convert_blob_length | |||
| ) |
Definition at line 8139 of file sql_select.cc.
References BLOB_FLAG, Field::charset(), Field::field_name, Field::flags, HA_OPTION_PACK_RECORD, Field::init(), Item::maybe_null, Field::maybe_null(), MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VARCHAR, Field::new_field(), NO_DEFAULT_VALUE_FLAG, NOT_NULL_FLAG, Field::orig_table, Item_field::result_field, st_table::s, Field::table, Field::type(), and UINT_MAX16.
Referenced by Item_sum_hybrid::create_tmp_field(), and create_tmp_field().
08142 { 08143 Field *new_field; 08144 08145 /* 08146 Make sure that the blob fits into a Field_varstring which has 08147 2-byte lenght. 08148 */ 08149 if (convert_blob_length && convert_blob_length < UINT_MAX16 && 08150 (org_field->flags & BLOB_FLAG)) 08151 new_field= new Field_varstring(convert_blob_length, 08152 org_field->maybe_null(), 08153 org_field->field_name, table->s, 08154 org_field->charset()); 08155 else 08156 new_field= org_field->new_field(thd->mem_root, table, 08157 table == org_field->table); 08158 if (new_field) 08159 { 08160 new_field->init(table); 08161 new_field->orig_table= org_field->orig_table; 08162 if (item) 08163 item->result_field= new_field; 08164 else 08165 new_field->field_name= name; 08166 new_field->flags|= (org_field->flags & NO_DEFAULT_VALUE_FLAG); 08167 if (org_field->maybe_null() || (item && item->maybe_null)) 08168 new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join 08169 if (org_field->type() == MYSQL_TYPE_VAR_STRING || 08170 org_field->type() == MYSQL_TYPE_VARCHAR) 08171 table->s->db_create_options|= HA_OPTION_PACK_RECORD; 08172 } 08173 return new_field; 08174 }
Here is the call graph for this function:

Here is the caller graph for this function:

| TABLE* create_tmp_table | ( | THD * | thd, | |
| TMP_TABLE_PARAM * | param, | |||
| List< Item > & | fields, | |||
| ORDER * | group, | |||
| bool | distinct, | |||
| bool | save_sum_fields, | |||
| ulonglong | select_options, | |||
| ha_rows | rows_limit, | |||
| char * | alias | |||
| ) |
Definition at line 8496 of file sql_select.cc.
References ALIGN_SIZE, alloc_root(), args, AVG_STRING_LENGTH_TO_PACK_ROWS, bfill, bitmap_buffer_size, bitmap_lock_clear_bit(), bitmap_lock_set_next(), BLOB_FLAG, st_order::buff, bzero, Item::const_item(), CONVERT_IF_BIGGER_TO_BLOB, mySTL::copy(), create_myisam_tmp_table(), create_tmp_field(), create_tmp_field_for_schema(), current_pid, DBUG_ASSERT, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_table_share::default_values, err, st_order::field, FIELD_BLOB, Field::field_index, Field::field_length, FIELD_NORMAL, FIELD_SKIP_ENDSPACE, FIELD_TYPE_BIT, FIELDFLAG_BINARY, Field::flags, fn_format(), FN_REFLEN, free_root(), free_tmp_table(), get_new_handler(), GROUP_FLAG, HA_END_SPACE_ARE_EQUAL, HA_KEY_ALG_UNDEF, HA_KEYTYPE_BINARY, HA_KEYTYPE_TEXT, HA_KEYTYPE_VARTEXT1, HA_KEYTYPE_VARTEXT2, HA_NOSAME, HA_NULL_ARE_EQUAL, HA_OPEN_KEYFILE, HA_OPEN_RNDFILE, heap_hton, init_sql_alloc(), init_tmp_table_share(), int(), Field::is_real_null(), st_order::item, keyinfo, LOCK_status, Item::marker, MAX_BLOB_WIDTH, MAX_KEY, memcpy, mi_portable_sizeof_char_ptr, MI_UNIQUE_HASH_LENGTH, min, MIN_STRING_LENGTH_TO_PACK_ROWS, Field::move_field(), Field::move_field_offset(), multi_alloc_root(), MY_BIT_NONE, my_charset_bin, MY_REPLACE_EXT, MY_UNPACK_FILENAME, MYF, myisam_hton, MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR, new(), Field::new_key_field(), st_order::next, Item::next, Field::NONE, NOT_NULL_FLAG, NULL, NullS, open_tmp_table(), OPTION_BIG_TABLES, Field::pack_length(), path, pos(), Field::ptr, RATIO_TO_PACK_ROWS, Field::real_type(), recinfo, reclength, st_table::record, Field::reset(), st_table::s, SELECT_SMALL_RESULT, set_if_bigger, set_if_smaller, Field::set_notnull(), Field::set_null(), setup_tmp_table_column_bitmaps(), statistic_increment, store_record, STRING_TOTAL_LENGTH_TO_PACK_ROWS, strlen(), strmov(), Item::SUM_FUNC_ITEM, Field::table, TABLE_ALLOC_BLOCK_SIZE, Field::table_name, temp_pool, test, test_flags, TEST_KEEP_TMP_TABLES, TL_WRITE, tmp_file_prefix, TMP_TABLE_ALL_COLUMNS, TMP_TABLE_FORCE_MYISAM, Field::type(), Item::type(), use_temp_pool, and Item::with_sum_func.
Referenced by JOIN::exec(), Item_sum_count_distinct::setup(), and Item_func_group_concat::setup().
08500 { 08501 MEM_ROOT *mem_root_save, own_root; 08502 TABLE *table; 08503 TABLE_SHARE *share; 08504 uint i,field_count,null_count,null_pack_length; 08505 uint copy_func_count= param->func_count; 08506 uint hidden_null_count, hidden_null_pack_length, hidden_field_count; 08507 uint blob_count,group_null_items, string_count; 08508 uint temp_pool_slot=MY_BIT_NONE; 08509 ulong reclength, string_total_length, fieldnr= 0; 08510 bool using_unique_constraint= 0; 08511 bool use_packed_rows= 0; 08512 bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS); 08513 char *tmpname,path[FN_REFLEN]; 08514 byte *pos, *group_buff, *bitmaps; 08515 uchar *null_flags; 08516 Field **reg_field, **from_field, **default_field; 08517 uint *blob_field; 08518 Copy_field *copy=0; 08519 KEY *keyinfo; 08520 KEY_PART_INFO *key_part_info; 08521 Item **copy_func; 08522 MI_COLUMNDEF *recinfo; 08523 uint total_uneven_bit_length= 0; 08524 bool force_copy_fields= param->force_copy_fields; 08525 DBUG_ENTER("create_tmp_table"); 08526 DBUG_PRINT("enter", 08527 ("distinct: %d save_sum_fields: %d rows_limit: %lu group: %d", 08528 (int) distinct, (int) save_sum_fields, 08529 (ulong) rows_limit,test(group))); 08530 08531 statistic_increment(thd->status_var.created_tmp_tables, &LOCK_status); 08532 08533 if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES)) 08534 temp_pool_slot = bitmap_lock_set_next(&temp_pool); 08535 08536 if (temp_pool_slot != MY_BIT_NONE) // we got a slot 08537 sprintf(path, "%s_%lx_%i", tmp_file_prefix, 08538 current_pid, temp_pool_slot); 08539 else 08540 { 08541 /* if we run out of slots or we are not using tempool */ 08542 sprintf(path,"%s%lx_%lx_%x", tmp_file_prefix,current_pid, 08543 thd->thread_id, thd->tmp_table++); 08544 } 08545 08546 /* 08547 No need to change table name to lower case as we are only creating 08548 MyISAM or HEAP tables here 08549 */ 08550 fn_format(path, path, mysql_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME); 08551 08552 if (group) 08553 { 08554 if (!param->quick_group) 08555 group=0; // Can't use group key 08556 else for (ORDER *tmp=group ; tmp ; tmp=tmp->next) 08557 { 08558 (*tmp->item)->marker=4; // Store null in key 08559 if ((*tmp->item)->max_length >= CONVERT_IF_BIGGER_TO_BLOB) 08560 using_unique_constraint=1; 08561 } 08562 if (param->group_length >= MAX_BLOB_WIDTH) 08563 using_unique_constraint=1; 08564 if (group) 08565 distinct=0; // Can't use distinct 08566 } 08567 08568 field_count=param->field_count+param->func_count+param->sum_func_count; 08569 hidden_field_count=param->hidden_field_count; 08570 08571 /* 08572 When loose index scan is employed as access method, it already 08573 computes all groups and the result of all aggregate functions. We 08574 make space for the items of the aggregate function in the list of 08575 functions TMP_TABLE_PARAM::items_to_copy, so that the values of 08576 these items are stored in the temporary table. 08577 */ 08578 if (param->precomputed_group_by) 08579 copy_func_count+= param->sum_func_count; 08580 08581 init_sql_alloc(&own_root, TABLE_ALLOC_BLOCK_SIZE, 0); 08582 08583 if (!multi_alloc_root(&own_root, 08584 &table, sizeof(*table), 08585 &share, sizeof(*share), 08586 ®_field, sizeof(Field*) * (field_count+1), 08587 &default_field, sizeof(Field*) * (field_count), 08588 &blob_field, sizeof(uint)*(field_count+1), 08589 &from_field, sizeof(Field*)*field_count, 08590 ©_func, sizeof(*copy_func)*(copy_func_count+1), 08591 ¶m->keyinfo, sizeof(*param->keyinfo), 08592 &key_part_info, 08593 sizeof(*key_part_info)*(param->group_parts+1), 08594 ¶m->start_recinfo, 08595 sizeof(*param->recinfo)*(field_count*2+4), 08596 &tmpname, (uint) strlen(path)+1, 08597 &group_buff, (group && ! using_unique_constraint ? 08598 param->group_length : 0), 08599 &bitmaps, bitmap_buffer_size(field_count)*2, 08600 NullS)) 08601 { 08602 if (temp_pool_slot != MY_BIT_NONE) 08603 bitmap_lock_clear_bit(&temp_pool, temp_pool_slot); 08604 DBUG_RETURN(NULL); /* purecov: inspected */ 08605 } 08606 /* Copy_field belongs to TMP_TABLE_PARAM, allocate it in THD mem_root */ 08607 if (!(param->copy_field=
