My Project
Typedefs | Functions
sql_tmp_table.h File Reference

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

TABLEcreate_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)
TABLEcreate_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)
TABLEcreate_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.
Fieldcreate_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)
Fieldcreate_tmp_field_from_field (THD *thd, Field *org_field, const char *name, TABLE *table, Item_field *item)

Detailed Description

Temporary table handling functions.


Function Documentation

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.

Parameters:
thdTHD reference
tableTable reference
start_recinfoEngine's column descriptions
recinfo[in,out]End of engine's column descriptions
errorReason why inserting into MEMORY table failed.
ignore_last_dupIf 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.

Parameters:
thdThread handler
tableTemporary table
itemItem to create a field for
typeType of item (normally item->type)
copy_funcIf set and item is a function, store copy of item in this array
from_fieldif field will be created using other field as example, pointer example field will be written here
default_fieldIf field has a default value field, store it here
group1 if we are going to do a relative group by on result
modify_item1 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
Return values:
NULLon error
new_createdfield
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.

Parameters:
thdThread handler
org_fieldfield from which new field will be created
nameNew field name
tableTemporary 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
Return values:
NULLon error
new_createdfield
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.

Parameters:
thdconnection handle
field_listlist of column definitions
Returns:
0 if out of memory, TABLE object in case of success
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.

Parameters:
tableTable object that describes the table to be instantiated
keyinfoDescription of the index (there is always one index)
start_recinfoColumn descriptions
recinfoINOUT End of column descriptions
optionsOption bits
traceOptimizer trace to write info to

Creates tmp table and opens it.

Returns:
FALSE - OK TRUE - Error
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines