summaryrefslogtreecommitdiff
path: root/sql/sql_select.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_select.h')
-rw-r--r--sql/sql_select.h78
1 files changed, 63 insertions, 15 deletions
diff --git a/sql/sql_select.h b/sql/sql_select.h
index ccdd66d5b95..6ab4463605b 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -57,16 +57,16 @@ typedef struct st_table_ref
*/
key_part_map null_rejecting;
table_map depend_map; // Table depends on these tables.
- byte *null_ref_key; // null byte position in the key_buf.
- // used for REF_OR_NULL optimization.
+ /* null byte position in the key_buf. Used for REF_OR_NULL optimization */
+ byte *null_ref_key;
} TABLE_REF;
+
/*
-** CACHE_FIELD and JOIN_CACHE is used on full join to cache records in outer
-** table
+ CACHE_FIELD and JOIN_CACHE is used on full join to cache records in outer
+ table
*/
-
typedef struct st_cache_field {
char *str;
uint length,blob_length;
@@ -84,7 +84,7 @@ typedef struct st_join_cache {
/*
-** The structs which holds the join connections and join states
+ The structs which holds the join connections and join states
*/
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,
@@ -104,6 +104,7 @@ typedef enum_nested_loop_state
typedef int (*Read_record_func)(struct st_join_table *tab);
Next_select_func setup_end_select_func(JOIN *join);
+
typedef struct st_join_table {
st_join_table() {} /* Remove gcc warning */
TABLE *table;
@@ -128,13 +129,28 @@ typedef struct st_join_table {
key_map checked_keys; /* Keys checked in find_best */
key_map needed_reg;
key_map keys; /* all keys with can be used */
- ha_rows records,found_records,read_time;
+
+ /* Either #rows in the table or 1 for const table. */
+ ha_rows records;
+ /*
+ Number of records that will be scanned (yes scanned, not returned) by the
+ best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
+ */
+ ha_rows found_records;
+ /*
+ Cost of accessing the table using "ALL" or range/index_merge access
+ method (but not 'index' for some reason), i.e. this matches method which
+ E(#records) is in found_records.
+ */
+ ha_rows read_time;
+
table_map dependent,key_dependent;
uint use_quick,index;
uint status; // Save status for cache
uint used_fields,used_fieldlength,used_blobs;
enum join_type type;
bool cached_eq_ref_table,eq_ref_table,not_used_in_distinct;
+ bool sorted;
TABLE_REF ref;
JOIN_CACHE cache;
JOIN *join;
@@ -155,15 +171,38 @@ enum_nested_loop_state sub_select_cache(JOIN *join, JOIN_TAB *join_tab, bool
enum_nested_loop_state sub_select(JOIN *join,JOIN_TAB *join_tab, bool
end_of_records);
-
-typedef struct st_position /* Used in find_best */
+/*
+ Information about a position of table within a join order. Used in join
+ optimization.
+*/
+typedef struct st_position
{
+ /*
+ The "fanout": number of output rows that will be produced (after
+ pushed down selection condition is applied) per each row combination of
+ previous tables.
+ */
double records_read;
+
+ /*
+ Cost accessing the table in course of the entire complete join execution,
+ i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
+ number the access method will be invoked.
+ */
double read_time;
JOIN_TAB *table;
+
+ /*
+ NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used.
+ Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
+ */
KEYUSE *key;
+
+ /* If ref-based access is used: bitmap of tables this table depends on */
+ table_map ref_depend_map;
} POSITION;
+
typedef struct st_rollup
{
enum State { STATE_NONE, STATE_INITED, STATE_READY };
@@ -462,12 +501,13 @@ public:
store_key(THD *thd, Field *field_arg, char *ptr, char *null, uint length)
:null_ptr(null), err(0), null_key(0)
{
- if (field_arg->type() == FIELD_TYPE_BLOB)
+ if (field_arg->type() == MYSQL_TYPE_BLOB)
{
- /* Key segments are always packed with a 2 byte length prefix */
- to_field=new Field_varstring(ptr, length, 2, (uchar*) null, 1,
- Field::NONE, field_arg->field_name,
- field_arg->table, field_arg->charset());
+ /* Key segments are always packed with a 2 byte length prefix */
+ to_field= new Field_varstring(ptr, length, 2, (uchar*) null, 1,
+ Field::NONE, field_arg->field_name,
+ field_arg->table->s, field_arg->charset());
+ to_field->init(field_arg->table);
}
else
to_field=field_arg->new_key_field(thd->mem_root, field_arg->table,
@@ -497,7 +537,11 @@ class store_key_field: public store_key
}
enum store_key_result copy()
{
+ TABLE *table= copy_field.to_field->table;
+ my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
+ table->write_set);
copy_field.do_copy(&copy_field);
+ dbug_tmp_restore_column_map(table->write_set, old_map);
null_key= to_field->is_null();
return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
}
@@ -518,7 +562,11 @@ public:
{}
enum store_key_result copy()
{
+ TABLE *table= to_field->table;
+ my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
+ table->write_set);
int res= item->save_in_field(to_field, 1);
+ dbug_tmp_restore_column_map(table->write_set, old_map);
null_key= to_field->is_null() || item->null_value;
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
}
@@ -556,7 +604,7 @@ public:
const char *name() const { return "const"; }
};
-bool cp_buffer_from_ref(THD *thd, TABLE_REF *ref);
+bool cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref);
bool error_if_full_join(JOIN *join);
int report_error(TABLE *table, int error);
int safe_index_read(JOIN_TAB *tab);