summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMagne Mahre <magne.mahre@sun.com>2010-02-11 18:04:32 +0100
committerMagne Mahre <magne.mahre@sun.com>2010-02-11 18:04:32 +0100
commit071688ba79a7a547001ecbe0150e45e116df945a (patch)
tree6d4a6335b80e1a6325ed09e98bc22b6841027f62 /sql
parentaf67056f28c164654686fe1f1bafddd98b2693f2 (diff)
parentb2ddac55637dc0552cb98b5ac21912f7ffaeb231 (diff)
downloadmariadb-git-071688ba79a7a547001ecbe0150e45e116df945a.tar.gz
merge
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_table.cc29
1 files changed, 14 insertions, 15 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 4f962de0a12..cc3aa0aa806 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3295,22 +3295,21 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
}
}
+ // Catch invalid use of partial keys
else if (!f_is_geom(sql_field->pack_flag) &&
- ((column->length > length &&
- !Field::type_can_have_key_part (sql_field->sql_type)) ||
- ((f_is_packed(sql_field->pack_flag) ||
- ((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
- (key_info->flags & HA_NOSAME))) &&
- column->length != length)))
- {
- /* Catch invalid uses of partial keys.
- A key is identified as 'partial' if column->length != length.
- A partial key is invalid if they data type does
- not allow it, or the field is packed (as in MyISAM),
- or the storage engine doesn't allow prefixed search and
- the key is primary key.
- */
-
+ // is the key partial?
+ column->length != length &&
+ // is prefix length bigger than field length?
+ (column->length > length ||
+ // can the field have a partial key?
+ !Field::type_can_have_key_part (sql_field->sql_type) ||
+ // a packed field can't be used in a partial key
+ f_is_packed(sql_field->pack_flag) ||
+ // does the storage engine allow prefixed search?
+ ((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
+ // and is this a 'unique' key?
+ (key_info->flags & HA_NOSAME))))
+ {
my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
DBUG_RETURN(TRUE);
}