summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sanja@askmonty.org>2010-09-08 09:26:17 +0300
committerunknown <sanja@askmonty.org>2010-09-08 09:26:17 +0300
commit11dc256ca4ee1057d1e918326b8c76fdbbca63cd (patch)
tree8f59ac5856cdd8515b959711d450188651952d46 /sql
parentd6a9b52269c2f64a8f793c4680eed9adece0a716 (diff)
downloadmariadb-git-11dc256ca4ee1057d1e918326b8c76fdbbca63cd.tar.gz
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_expression_cache.cc63
-rw-r--r--sql/sql_expression_cache.h3
-rw-r--r--sql/table.cc8
-rw-r--r--sql/table.h3
4 files changed, 13 insertions, 64 deletions
diff --git a/sql/sql_expression_cache.cc b/sql/sql_expression_cache.cc
index cbbafbd55c8..ca7c583292c 100644
--- a/sql/sql_expression_cache.cc
+++ b/sql/sql_expression_cache.cc
@@ -12,7 +12,7 @@ Expression_cache_tmptable::Expression_cache_tmptable(THD *thd,
List<Item*> &dependants,
Item *value)
:cache_table(NULL), table_thd(thd), list(&dependants), val(value),
- equalities(NULL), inited (0)
+ inited (0)
{
DBUG_ENTER("Expression_cache_tmptable::Expression_cache_tmptable");
DBUG_VOID_RETURN;
@@ -20,56 +20,6 @@ Expression_cache_tmptable::Expression_cache_tmptable(THD *thd,
/**
- Build and of equalities for the expression's parameters of certain types
-
- @details
- If the temporary table used as an expression cache contains fields of
- certain types then it's not enough to perform a lookup into the table to
- verify that there is no row in the table for a given set of parameters.
- Additionally for those fields we have to check equalities of the form
- fld=val, where val is the value of the parameter stored in the column
- fld.
- The function generates a conjunction of all such equality predicates
- and saves a pointer to it in the field 'equalities'.
-
- @retval FALSE OK
- @retval TRUE Error
-*/
-
-bool Expression_cache_tmptable::make_equalities()
-{
- List<Item> args;
- List_iterator_fast<Item*> li(*list);
- Item **ref;
- DBUG_ENTER("Expression_cache_tmptable::make_equalities");
-
- for (uint i= 1 /* skip result filed */; (ref= li++); i++)
- {
- Field *fld= cache_table->field[i];
- /* Only some field types should be checked after lookup */
- if (fld->type() == MYSQL_TYPE_VARCHAR ||
- fld->type() == MYSQL_TYPE_TINY_BLOB ||
- fld->type() == MYSQL_TYPE_MEDIUM_BLOB ||
- fld->type() == MYSQL_TYPE_LONG_BLOB ||
- fld->type() == MYSQL_TYPE_BLOB ||
- fld->type() == MYSQL_TYPE_VAR_STRING ||
- fld->type() == MYSQL_TYPE_STRING ||
- fld->type() == MYSQL_TYPE_NEWDECIMAL ||
- fld->type() == MYSQL_TYPE_DECIMAL)
- {
- args.push_front(new Item_func_eq(*ref, new Item_field(fld)));
- }
- }
- if (args.elements == 1)
- equalities= args.head();
- else
- equalities= new Item_cond_and(args);
-
- DBUG_RETURN(equalities->fix_fields(table_thd, &equalities));
-}
-
-
-/**
Field enumerator for TABLE::add_tmp_key
@param arg reference variable with current field number
@@ -166,7 +116,8 @@ void Expression_cache_tmptable::init()
if (cache_table->alloc_keys(1) ||
(cache_table->add_tmp_key(0, items.elements - 1,
&field_enumerator,
- (uchar*)&field_counter) < 0) ||
+ (uchar*)&field_counter,
+ TRUE) < 0) ||
ref.tmp_table_index_lookup_init(table_thd, cache_table->key_info, it,
TRUE))
{
@@ -193,12 +144,6 @@ void Expression_cache_tmptable::init()
goto error;
}
- if (make_equalities())
- {
- DBUG_PRINT("error", ("Creating equalities failed"));
- goto error;
- }
-
DBUG_VOID_RETURN;
error:
@@ -249,7 +194,7 @@ Expression_cache::result Expression_cache_tmptable::check_value(Item **value)
(uint)cache_table->status, (uint)ref.has_record));
if ((res= join_read_key2(table_thd, NULL, cache_table, &ref)) == 1)
DBUG_RETURN(ERROR);
- if (res || (equalities && !equalities->val_int()))
+ if (res)
{
subquery_cache_miss++;
DBUG_RETURN(MISS);
diff --git a/sql/sql_expression_cache.h b/sql/sql_expression_cache.h
index e931eca6091..d74e9f49178 100644
--- a/sql/sql_expression_cache.h
+++ b/sql/sql_expression_cache.h
@@ -60,7 +60,6 @@ public:
private:
void init();
- bool make_equalities();
/* tmp table parameters */
TMP_TABLE_PARAM cache_table_param;
@@ -78,8 +77,6 @@ private:
List<Item> items;
/* Value Item example */
Item *val;
- /* Expression to check after index lookup */
- Item *equalities;
/* Set on if the object has been succesfully initialized with init() */
bool inited;
};
diff --git a/sql/table.cc b/sql/table.cc
index 3a4ea3064be..2b1a85a74ea 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5162,6 +5162,7 @@ bool TABLE::alloc_keys(uint key_count)
@param next_field_no the call-back function that returns the number of
the field used as the next component of the key
@param arg the argument for the above function
+ @param unique Is it unique index
@details
The function adds a new key to the table that is assumed to be
@@ -5173,7 +5174,8 @@ bool TABLE::alloc_keys(uint key_count)
*/
bool TABLE::add_tmp_key(uint key, uint key_parts,
- uint (*next_field_no) (uchar *), uchar *arg)
+ uint (*next_field_no) (uchar *), uchar *arg,
+ bool unique)
{
DBUG_ASSERT(key < max_keys);
@@ -5192,6 +5194,8 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
keyinfo->key_length=0;
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
keyinfo->flags= HA_GENERATED_KEY;
+ if (unique)
+ keyinfo->flags|= HA_NOSAME;
sprintf(buf, "key%i", key);
if (!(keyinfo->name= strdup_root(&mem_root, buf)))
return TRUE;
@@ -5230,6 +5234,8 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
{
key_part_info->store_length+= HA_KEY_NULL_LENGTH;
keyinfo->key_length+= HA_KEY_NULL_LENGTH;
+ if (unique)
+ keyinfo->flags|= HA_NULL_ARE_EQUAL; // def. that NULL == NULL
}
if ((*reg_field)->type() == MYSQL_TYPE_BLOB ||
(*reg_field)->real_type() == MYSQL_TYPE_VARCHAR)
diff --git a/sql/table.h b/sql/table.h
index 5102955e2ad..3922e1dd6bd 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -920,7 +920,8 @@ struct st_table {
{ return s->version != refresh_version; }
bool alloc_keys(uint key_count);
bool add_tmp_key(uint key, uint key_parts,
- uint (*next_field_no) (uchar *), uchar *arg);
+ uint (*next_field_no) (uchar *), uchar *arg,
+ bool unique);
bool is_children_attached(void);
inline void enable_keyread()
{