My Project
|
Temporary table handling functions. More...
#include "sql_list.h"
#include "sql_class.h"
#include "my_base.h"
#include "field.h"
#include "item.h"
Go to the source code of this file.
Typedefs | |
typedef struct st_order | ORDER |
typedef struct st_columndef | MI_COLUMNDEF |
Functions | |
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, const char *table_alias) |
TABLE * | create_virtual_tmp_table (THD *thd, List< Create_field > &field_list) |
bool | create_myisam_from_heap (THD *thd, TABLE *table, MI_COLUMNDEF *start_recinfo, MI_COLUMNDEF **recinfo, int error, bool ignore_last_dup, bool *is_duplicate) |
void | free_tmp_table (THD *thd, TABLE *entry) |
TABLE * | create_duplicate_weedout_tmp_table (THD *thd, uint uniq_tuple_length_arg, SJ_TMP_TABLE *sjtbl) |
bool | instantiate_tmp_table (TABLE *table, KEY *keyinfo, MI_COLUMNDEF *start_recinfo, MI_COLUMNDEF **recinfo, ulonglong options, my_bool big_tables, Opt_trace_context *trace) |
Instantiates temporary table. | |
Field * | create_tmp_field (THD *thd, TABLE *table, Item *item, Item::Type type, Item ***copy_func, Field **from_field, Field **default_field, bool group, bool modify_item, bool table_cant_handle_bit_fields, bool make_copy_field) |
Field * | create_tmp_field_from_field (THD *thd, Field *org_field, const char *name, TABLE *table, Item_field *item) |
Temporary table handling functions.
bool create_myisam_from_heap | ( | THD * | thd, |
TABLE * | table, | ||
MI_COLUMNDEF * | start_recinfo, | ||
MI_COLUMNDEF ** | recinfo, | ||
int | error, | ||
bool | ignore_last_dup, | ||
bool * | is_duplicate | ||
) |
If a MEMORY table gets full, create a disk-based table and copy all rows to this.
thd | THD reference |
table | Table reference |
start_recinfo | Engine's column descriptions |
recinfo[in,out] | End of engine's column descriptions |
error | Reason why inserting into MEMORY table failed. |
ignore_last_dup | If true, ignore duplicate key error for last inserted key (see detailed description below). |
is_duplicate[out] | if non-NULL and ignore_last_dup is TRUE, return TRUE if last key was a duplicate, and FALSE otherwise. |
Function can be called with any error code, but only HA_ERR_RECORD_FILE_FULL will be handled, all other errors cause a fatal error to be thrown. The function creates a disk-based temporary table, copies all records from the MEMORY table into this new table, deletes the old table and switches to use the new table within the table handle. The function uses table->record[1] as a temporary buffer while copying.
The function assumes that table->record[0] contains the row that caused the error when inserting into the MEMORY table (the "last row"). After all existing rows have been copied to the new table, the last row is attempted to be inserted as well. If ignore_last_dup is true, this row can be a duplicate of an existing row without throwing an error. If is_duplicate is non-NULL, an indication of whether the last row was a duplicate is returned.
Field* create_tmp_field | ( | THD * | thd, |
TABLE * | table, | ||
Item * | item, | ||
Item::Type | type, | ||
Item *** | copy_func, | ||
Field ** | from_field, | ||
Field ** | default_field, | ||
bool | group, | ||
bool | modify_item, | ||
bool | table_cant_handle_bit_fields, | ||
bool | make_copy_field | ||
) |
Create field for temporary table.
thd | Thread handler |
table | Temporary table |
item | Item to create a field for |
type | Type of item (normally item->type) |
copy_func | If set and item is a function, store copy of item in this array |
from_field | if field will be created using other field as example, pointer example field will be written here |
default_field | If field has a default value field, store it here |
group | 1 if we are going to do a relative group by on result |
modify_item | 1 if item->result_field should point to new item. This is relevent for how fill_record() is going to work: If modify_item is 1 then fill_record() will update the record in the original table. If modify_item is 0 then fill_record() will update the temporary table |
NULL | on error |
new_created | field |
Field* create_tmp_field_from_field | ( | THD * | thd, |
Field * | org_field, | ||
const char * | name, | ||
TABLE * | table, | ||
Item_field * | item | ||
) |
Create field for temporary table from given field.
thd | Thread handler |
org_field | field from which new field will be created |
name | New field name |
table | Temporary table |
item | !=NULL if item->result_field should point to new field. This is relevant for how fill_record() is going to work: If item != NULL then fill_record() will update the record in the original table. If item == NULL then fill_record() will update the temporary table |
NULL | on error |
new_created | field |
TABLE* create_virtual_tmp_table | ( | THD * | thd, |
List< Create_field > & | field_list | ||
) |
General routine to change field->ptr of a NULL-terminated array of Field objects. Useful when needed to call val_int, val_str or similar and the field data is not in table->record[0] but in some other structure. set_key_field_ptr changes all fields of an index using a key_info object. All methods presume that there is at least one field to change.
Create a reduced TABLE object with properly set up Field list from a list of field definitions.
The created table doesn't have a table handler associated with it, has no keys, no group/distinct, no copy_funcs array. The sole purpose of this TABLE object is to use the power of Field class to read/write data to/from table->record[0]. Then one can store the record in any container (RB tree, hash, etc). The table is created in THD mem_root, so are the table's fields. Consequently, if you don't BLOB fields, you don't need to free it.
thd | connection handle |
field_list | list of column definitions |
bool instantiate_tmp_table | ( | TABLE * | table, |
KEY * | keyinfo, | ||
MI_COLUMNDEF * | start_recinfo, | ||
MI_COLUMNDEF ** | recinfo, | ||
ulonglong | options, | ||
my_bool | big_tables, | ||
Opt_trace_context * | trace | ||
) |
Instantiates temporary table.
table | Table object that describes the table to be instantiated |
keyinfo | Description of the index (there is always one index) |
start_recinfo | Column descriptions |
recinfo | INOUT End of column descriptions |
options | Option bits |
trace | Optimizer trace to write info to |
Creates tmp table and opens it.