Commit cbe90dd1 authored by Alexander Nozdrin's avatar Alexander Nozdrin

Auto-merge from mysql-next-mr-bugfixing.

parents c4f1de9f 86db818b
...@@ -1354,3 +1354,15 @@ DROP i, ...@@ -1354,3 +1354,15 @@ DROP i,
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1; AUTO_INCREMENT = 1;
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255)));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
CREATE TABLE t1 (a CHAR(1));
ALTER TABLE t1 ADD PRIMARY KEY (a(20));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
ALTER TABLE t1 ADD KEY (a(20));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
CREATE UNIQUE INDEX i1 ON t1 (a(20));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
CREATE INDEX i2 ON t1 (a(20));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
DROP TABLE t1;
...@@ -1058,3 +1058,33 @@ SELECT Polygon(12345123,''); ...@@ -1058,3 +1058,33 @@ SELECT Polygon(12345123,'');
Polygon(12345123,'') Polygon(12345123,'')
NULL NULL
End of 5.1 tests End of 5.1 tests
CREATE TABLE t1(
col0 BINARY NOT NULL,
col2 TIMESTAMP,
SPATIAL INDEX i1 (col0)
) ENGINE=MyISAM;
ERROR 42000: A SPATIAL index may only contain a geometrical type column
CREATE TABLE t1 (
col0 BINARY NOT NULL,
col2 TIMESTAMP
) ENGINE=MyISAM;
CREATE SPATIAL INDEX idx0 ON t1(col0);
ERROR 42000: A SPATIAL index may only contain a geometrical type column
ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
ERROR 42000: A SPATIAL index may only contain a geometrical type column
CREATE TABLE t2 (
col0 INTEGER NOT NULL,
col1 POINT,
col2 POINT
);
CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
ERROR HY000: Incorrect arguments to SPATIAL INDEX
CREATE TABLE t3 (
col0 INTEGER NOT NULL,
col1 POINT,
col2 LINESTRING,
SPATIAL INDEX i1 (col1, col2)
);
ERROR HY000: Incorrect arguments to SPATIAL INDEX
DROP TABLE t1;
DROP TABLE t2;
...@@ -2686,7 +2686,7 @@ a c COUNT(DISTINCT c, a, b) ...@@ -2686,7 +2686,7 @@ a c COUNT(DISTINCT c, a, b)
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
2 1 1 1 1 1
2 1 1 2 1 1
2 1 1 2 1 1
2 1 1 2 1 1
...@@ -2714,7 +2714,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -2714,7 +2714,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range NULL a 10 NULL 9 Using index for group-by 1 SIMPLE t2 range NULL a 10 NULL 9 Using index for group-by
SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a;
a COUNT(DISTINCT b) SUM(DISTINCT b) a COUNT(DISTINCT b) SUM(DISTINCT b)
2 8 36 1 8 36
2 8 36 2 8 36
EXPLAIN SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a; EXPLAIN SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
...@@ -2761,7 +2761,7 @@ SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c; ...@@ -2761,7 +2761,7 @@ SELECT 42 * (a + c + COUNT(DISTINCT c, a, b)) FROM t2 GROUP BY a, b, c;
126 126
126 126
126 126
168 126
168 168
168 168
168 168
...@@ -2779,3 +2779,24 @@ SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a; ...@@ -2779,3 +2779,24 @@ SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a;
10 10
DROP TABLE t1,t2; DROP TABLE t1,t2;
# end of WL#3220 tests # end of WL#3220 tests
#
# Bug#50539: Wrong result when loose index scan is used for an aggregate
# function with distinct
#
CREATE TABLE t1 (
f1 int(11) NOT NULL DEFAULT '0',
f2 char(1) NOT NULL DEFAULT '',
PRIMARY KEY (f1,f2)
) ;
insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'),
(3, 'A'), (3, 'B'), (3, 'C'), (3, 'D');
SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
f1 COUNT(DISTINCT f2)
1 3
2 1
3 4
explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL PRIMARY 5 NULL 9 Using index for group-by (scanning)
drop table t1;
# End of test#50539.
...@@ -1089,3 +1089,31 @@ ALTER TABLE t1 ...@@ -1089,3 +1089,31 @@ ALTER TABLE t1
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1; AUTO_INCREMENT = 1;
DROP TABLE t1; DROP TABLE t1;
#
# Bug#50542 5.5.x doesn't check length of key prefixes:
# corruption and crash results
#
# This case is related to Bug#31031 (above)
# A statement where the index key is larger/wider than
# the column type, should cause an error
#
--error ER_WRONG_SUB_KEY
CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255)));
# Test other variants of creating indices
CREATE TABLE t1 (a CHAR(1));
# ALTER TABLE
--error ER_WRONG_SUB_KEY
ALTER TABLE t1 ADD PRIMARY KEY (a(20));
--error ER_WRONG_SUB_KEY
ALTER TABLE t1 ADD KEY (a(20));
# CREATE INDEX
--error ER_WRONG_SUB_KEY
CREATE UNIQUE INDEX i1 ON t1 (a(20));
--error ER_WRONG_SUB_KEY
CREATE INDEX i2 ON t1 (a(20));
# cleanup
DROP TABLE t1;
...@@ -726,3 +726,48 @@ SELECT Polygon(1234512,''); ...@@ -726,3 +726,48 @@ SELECT Polygon(1234512,'');
SELECT Polygon(12345123,''); SELECT Polygon(12345123,'');
--echo End of 5.1 tests --echo End of 5.1 tests
#
# Bug #50574 5.5.x allows spatial indexes on non-spatial
# columns, causing crashes!
#
--error ER_SPATIAL_MUST_HAVE_GEOM_COL
CREATE TABLE t1(
col0 BINARY NOT NULL,
col2 TIMESTAMP,
SPATIAL INDEX i1 (col0)
) ENGINE=MyISAM;
# Test other ways to add indices
CREATE TABLE t1 (
col0 BINARY NOT NULL,
col2 TIMESTAMP
) ENGINE=MyISAM;
--error ER_SPATIAL_MUST_HAVE_GEOM_COL
CREATE SPATIAL INDEX idx0 ON t1(col0);
--error ER_SPATIAL_MUST_HAVE_GEOM_COL
ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
CREATE TABLE t2 (
col0 INTEGER NOT NULL,
col1 POINT,
col2 POINT
);
--error ER_WRONG_ARGUMENTS
CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
--error ER_WRONG_ARGUMENTS
CREATE TABLE t3 (
col0 INTEGER NOT NULL,
col1 POINT,
col2 LINESTRING,
SPATIAL INDEX i1 (col1, col2)
);
# cleanup
DROP TABLE t1;
DROP TABLE t2;
...@@ -1166,3 +1166,22 @@ SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a; ...@@ -1166,3 +1166,22 @@ SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo # end of WL#3220 tests --echo # end of WL#3220 tests
--echo #
--echo # Bug#50539: Wrong result when loose index scan is used for an aggregate
--echo # function with distinct
--echo #
CREATE TABLE t1 (
f1 int(11) NOT NULL DEFAULT '0',
f2 char(1) NOT NULL DEFAULT '',
PRIMARY KEY (f1,f2)
) ;
insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'),
(3, 'A'), (3, 'B'), (3, 'C'), (3, 'D');
SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
drop table t1;
--echo # End of test#50539.
...@@ -4717,10 +4717,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli, ...@@ -4717,10 +4717,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
thd->warning_info->opt_clear_warning_info(thd->query_id); thd->warning_info->opt_clear_warning_info(thd->query_id);
TABLE_LIST tables; TABLE_LIST tables;
bzero((char*) &tables,sizeof(tables)); tables.init_one_table(thd->db, table_name, TL_WRITE);
tables.db= thd->strmake(thd->db, thd->db_length);
tables.alias = tables.table_name = (char*) table_name;
tables.lock_type = TL_WRITE;
tables.updating= 1; tables.updating= 1;
// the table will be opened in mysql_load // the table will be opened in mysql_load
......
...@@ -10955,17 +10955,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::get_next() ...@@ -10955,17 +10955,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::get_next()
} while ((result == HA_ERR_KEY_NOT_FOUND || result == HA_ERR_END_OF_FILE) && } while ((result == HA_ERR_KEY_NOT_FOUND || result == HA_ERR_END_OF_FILE) &&
is_last_prefix != 0); is_last_prefix != 0);
if (result == 0) if (result == HA_ERR_KEY_NOT_FOUND)
{
/*
Partially mimic the behavior of end_select_send. Copy the
field data from Item_field::field into Item_field::result_field
of each non-aggregated field (the group fields, and optionally
other fields in non-ANSI SQL mode).
*/
copy_fields(&join->tmp_table_param);
}
else if (result == HA_ERR_KEY_NOT_FOUND)
result= HA_ERR_END_OF_FILE; result= HA_ERR_END_OF_FILE;
DBUG_RETURN(result); DBUG_RETURN(result);
......
...@@ -6316,3 +6316,6 @@ ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT ...@@ -6316,3 +6316,6 @@ ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction" eng "Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction"
ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot change the binlog direct flag inside a stored function or trigger" eng "Cannot change the binlog direct flag inside a stored function or trigger"
ER_SPATIAL_MUST_HAVE_GEOM_COL 42000
eng "A SPATIAL index may only contain a geometrical type column"
...@@ -12316,6 +12316,12 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), ...@@ -12316,6 +12316,12 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
if (!end_of_records) if (!end_of_records)
{ {
int error; int error;
if (join->tables &&
join->join_tab->is_using_loose_index_scan())
{
/* Copy non-aggregated fields when loose index scan is used. */
copy_fields(&join->tmp_table_param);
}
if (join->having && join->having->val_int() == 0) if (join->having && join->having->val_int() == 0)
DBUG_RETURN(NESTED_LOOP_OK); // Didn't match having DBUG_RETURN(NESTED_LOOP_OK); // Didn't match having
error=0; error=0;
......
...@@ -3196,11 +3196,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3196,11 +3196,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
{ {
column->length*= sql_field->charset->mbmaxlen; column->length*= sql_field->charset->mbmaxlen;
if (key->type == Key::SPATIAL && column->length) if (key->type == Key::SPATIAL)
{ {
my_error(ER_WRONG_SUB_KEY, MYF(0)); if (column->length)
DBUG_RETURN(TRUE); {
} my_error(ER_WRONG_SUB_KEY, MYF(0));
DBUG_RETURN(TRUE);
}
if (!f_is_geom(sql_field->pack_flag))
{
my_error(ER_SPATIAL_MUST_HAVE_GEOM_COL, MYF(0));
DBUG_RETURN(TRUE);
}
}
if (f_is_blob(sql_field->pack_flag) || if (f_is_blob(sql_field->pack_flag) ||
(f_is_geom(sql_field->pack_flag) && key->type != Key::SPATIAL)) (f_is_geom(sql_field->pack_flag) && key->type != Key::SPATIAL))
...@@ -3295,22 +3303,21 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3295,22 +3303,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) && else if (!f_is_geom(sql_field->pack_flag) &&
((column->length > length && // is the key partial?
!Field::type_can_have_key_part (sql_field->sql_type)) || column->length != length &&
((f_is_packed(sql_field->pack_flag) || // is prefix length bigger than field length?
((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) && (column->length > length ||
(key_info->flags & HA_NOSAME))) && // can the field have a partial key?
column->length != length))) !Field::type_can_have_key_part (sql_field->sql_type) ||
{ // a packed field can't be used in a partial key
/* Catch invalid uses of partial keys. f_is_packed(sql_field->pack_flag) ||
A key is identified as 'partial' if column->length != length. // does the storage engine allow prefixed search?
A partial key is invalid if they data type does ((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
not allow it, or the field is packed (as in MyISAM), // and is this a 'unique' key?
or the storage engine doesn't allow prefixed search and (key_info->flags & HA_NOSAME))))
the key is primary key. {
*/
my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0)); my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment