Skip to content

Commit a8eeb3f

Browse files
author
Alexander Nozdrin
committed
Auto-merge from mysql-next-mr-bugfixing.
2 parents ec9f4c7 + 7313dae commit a8eeb3f

File tree

11 files changed

+195
-37
lines changed

11 files changed

+195
-37
lines changed

mysql-test/r/alter_table.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,3 +1354,15 @@ DROP i,
13541354
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
13551355
AUTO_INCREMENT = 1;
13561356
DROP TABLE t1;
1357+
CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255)));
1358+
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
1359+
CREATE TABLE t1 (a CHAR(1));
1360+
ALTER TABLE t1 ADD PRIMARY KEY (a(20));
1361+
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
1362+
ALTER TABLE t1 ADD KEY (a(20));
1363+
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
1364+
CREATE UNIQUE INDEX i1 ON t1 (a(20));
1365+
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
1366+
CREATE INDEX i2 ON t1 (a(20));
1367+
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
1368+
DROP TABLE t1;

mysql-test/r/gis.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,3 +1058,33 @@ SELECT Polygon(12345123,'');
10581058
Polygon(12345123,'')
10591059
NULL
10601060
End of 5.1 tests
1061+
CREATE TABLE t1(
1062+
col0 BINARY NOT NULL,
1063+
col2 TIMESTAMP,
1064+
SPATIAL INDEX i1 (col0)
1065+
) ENGINE=MyISAM;
1066+
ERROR 42000: A SPATIAL index may only contain a geometrical type column
1067+
CREATE TABLE t1 (
1068+
col0 BINARY NOT NULL,
1069+
col2 TIMESTAMP
1070+
) ENGINE=MyISAM;
1071+
CREATE SPATIAL INDEX idx0 ON t1(col0);
1072+
ERROR 42000: A SPATIAL index may only contain a geometrical type column
1073+
ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
1074+
ERROR 42000: A SPATIAL index may only contain a geometrical type column
1075+
CREATE TABLE t2 (
1076+
col0 INTEGER NOT NULL,
1077+
col1 POINT,
1078+
col2 POINT
1079+
);
1080+
CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
1081+
ERROR HY000: Incorrect arguments to SPATIAL INDEX
1082+
CREATE TABLE t3 (
1083+
col0 INTEGER NOT NULL,
1084+
col1 POINT,
1085+
col2 LINESTRING,
1086+
SPATIAL INDEX i1 (col1, col2)
1087+
);
1088+
ERROR HY000: Incorrect arguments to SPATIAL INDEX
1089+
DROP TABLE t1;
1090+
DROP TABLE t2;

mysql-test/r/group_min_max.result

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ a c COUNT(DISTINCT c, a, b)
26862686
1 1 1
26872687
1 1 1
26882688
1 1 1
2689-
2 1 1
2689+
1 1 1
26902690
2 1 1
26912691
2 1 1
26922692
2 1 1
@@ -2714,7 +2714,7 @@ id select_type table type possible_keys key key_len ref rows Extra
27142714
1 SIMPLE t2 range NULL a 10 NULL 9 Using index for group-by
27152715
SELECT a, COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a;
27162716
a COUNT(DISTINCT b) SUM(DISTINCT b)
2717-
2 8 36
2717+
1 8 36
27182718
2 8 36
27192719
EXPLAIN SELECT COUNT(DISTINCT b), SUM(DISTINCT b) FROM t2 GROUP BY a;
27202720
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;
27612761
126
27622762
126
27632763
126
2764-
168
2764+
126
27652765
168
27662766
168
27672767
168
@@ -2779,3 +2779,24 @@ SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a;
27792779
10
27802780
DROP TABLE t1,t2;
27812781
# end of WL#3220 tests
2782+
#
2783+
# Bug#50539: Wrong result when loose index scan is used for an aggregate
2784+
# function with distinct
2785+
#
2786+
CREATE TABLE t1 (
2787+
f1 int(11) NOT NULL DEFAULT '0',
2788+
f2 char(1) NOT NULL DEFAULT '',
2789+
PRIMARY KEY (f1,f2)
2790+
) ;
2791+
insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'),
2792+
(3, 'A'), (3, 'B'), (3, 'C'), (3, 'D');
2793+
SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
2794+
f1 COUNT(DISTINCT f2)
2795+
1 3
2796+
2 1
2797+
3 4
2798+
explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
2799+
id select_type table type possible_keys key key_len ref rows Extra
2800+
1 SIMPLE t1 range NULL PRIMARY 5 NULL 9 Using index for group-by (scanning)
2801+
drop table t1;
2802+
# End of test#50539.

mysql-test/t/alter_table.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,31 @@ ALTER TABLE t1
10891089
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
10901090
AUTO_INCREMENT = 1;
10911091
DROP TABLE t1;
1092+
1093+
1094+
#
1095+
# Bug#50542 5.5.x doesn't check length of key prefixes:
1096+
# corruption and crash results
1097+
#
1098+
# This case is related to Bug#31031 (above)
1099+
# A statement where the index key is larger/wider than
1100+
# the column type, should cause an error
1101+
#
1102+
--error ER_WRONG_SUB_KEY
1103+
CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255)));
1104+
1105+
# Test other variants of creating indices
1106+
CREATE TABLE t1 (a CHAR(1));
1107+
# ALTER TABLE
1108+
--error ER_WRONG_SUB_KEY
1109+
ALTER TABLE t1 ADD PRIMARY KEY (a(20));
1110+
--error ER_WRONG_SUB_KEY
1111+
ALTER TABLE t1 ADD KEY (a(20));
1112+
# CREATE INDEX
1113+
--error ER_WRONG_SUB_KEY
1114+
CREATE UNIQUE INDEX i1 ON t1 (a(20));
1115+
--error ER_WRONG_SUB_KEY
1116+
CREATE INDEX i2 ON t1 (a(20));
1117+
# cleanup
1118+
DROP TABLE t1;
1119+

mysql-test/t/gis.test

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,48 @@ SELECT Polygon(1234512,'');
726726
SELECT Polygon(12345123,'');
727727

728728
--echo End of 5.1 tests
729+
730+
#
731+
# Bug #50574 5.5.x allows spatial indexes on non-spatial
732+
# columns, causing crashes!
733+
#
734+
--error ER_SPATIAL_MUST_HAVE_GEOM_COL
735+
CREATE TABLE t1(
736+
col0 BINARY NOT NULL,
737+
col2 TIMESTAMP,
738+
SPATIAL INDEX i1 (col0)
739+
) ENGINE=MyISAM;
740+
741+
# Test other ways to add indices
742+
CREATE TABLE t1 (
743+
col0 BINARY NOT NULL,
744+
col2 TIMESTAMP
745+
) ENGINE=MyISAM;
746+
747+
--error ER_SPATIAL_MUST_HAVE_GEOM_COL
748+
CREATE SPATIAL INDEX idx0 ON t1(col0);
749+
750+
--error ER_SPATIAL_MUST_HAVE_GEOM_COL
751+
ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0);
752+
753+
CREATE TABLE t2 (
754+
col0 INTEGER NOT NULL,
755+
col1 POINT,
756+
col2 POINT
757+
);
758+
759+
--error ER_WRONG_ARGUMENTS
760+
CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
761+
762+
--error ER_WRONG_ARGUMENTS
763+
CREATE TABLE t3 (
764+
col0 INTEGER NOT NULL,
765+
col1 POINT,
766+
col2 LINESTRING,
767+
SPATIAL INDEX i1 (col1, col2)
768+
);
769+
770+
# cleanup
771+
DROP TABLE t1;
772+
DROP TABLE t2;
773+

mysql-test/t/group_min_max.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,3 +1166,22 @@ SELECT (SUM(DISTINCT a) + MAX(b)) FROM t2 GROUP BY a;
11661166
DROP TABLE t1,t2;
11671167

11681168
--echo # end of WL#3220 tests
1169+
1170+
--echo #
1171+
--echo # Bug#50539: Wrong result when loose index scan is used for an aggregate
1172+
--echo # function with distinct
1173+
--echo #
1174+
CREATE TABLE t1 (
1175+
f1 int(11) NOT NULL DEFAULT '0',
1176+
f2 char(1) NOT NULL DEFAULT '',
1177+
PRIMARY KEY (f1,f2)
1178+
) ;
1179+
insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'),
1180+
(3, 'A'), (3, 'B'), (3, 'C'), (3, 'D');
1181+
1182+
SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
1183+
explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
1184+
1185+
drop table t1;
1186+
--echo # End of test#50539.
1187+

sql/log_event.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,10 +4717,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
47174717
thd->warning_info->opt_clear_warning_info(thd->query_id);
47184718

47194719
TABLE_LIST tables;
4720-
bzero((char*) &tables,sizeof(tables));
4721-
tables.db= thd->strmake(thd->db, thd->db_length);
4722-
tables.alias = tables.table_name = (char*) table_name;
4723-
tables.lock_type = TL_WRITE;
4720+
tables.init_one_table(thd->db, table_name, TL_WRITE);
47244721
tables.updating= 1;
47254722

47264723
// the table will be opened in mysql_load

sql/opt_range.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10955,17 +10955,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::get_next()
1095510955
} while ((result == HA_ERR_KEY_NOT_FOUND || result == HA_ERR_END_OF_FILE) &&
1095610956
is_last_prefix != 0);
1095710957

10958-
if (result == 0)
10959-
{
10960-
/*
10961-
Partially mimic the behavior of end_select_send. Copy the
10962-
field data from Item_field::field into Item_field::result_field
10963-
of each non-aggregated field (the group fields, and optionally
10964-
other fields in non-ANSI SQL mode).
10965-
*/
10966-
copy_fields(&join->tmp_table_param);
10967-
}
10968-
else if (result == HA_ERR_KEY_NOT_FOUND)
10958+
if (result == HA_ERR_KEY_NOT_FOUND)
1096910959
result= HA_ERR_END_OF_FILE;
1097010960

1097110961
DBUG_RETURN(result);

sql/share/errmsg-utf8.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6316,3 +6316,6 @@ ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
63166316
eng "Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction"
63176317
ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT
63186318
eng "Cannot change the binlog direct flag inside a stored function or trigger"
6319+
ER_SPATIAL_MUST_HAVE_GEOM_COL 42000
6320+
eng "A SPATIAL index may only contain a geometrical type column"
6321+

sql/sql_select.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12316,6 +12316,12 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
1231612316
if (!end_of_records)
1231712317
{
1231812318
int error;
12319+
if (join->tables &&
12320+
join->join_tab->is_using_loose_index_scan())
12321+
{
12322+
/* Copy non-aggregated fields when loose index scan is used. */
12323+
copy_fields(&join->tmp_table_param);
12324+
}
1231912325
if (join->having && join->having->val_int() == 0)
1232012326
DBUG_RETURN(NESTED_LOOP_OK); // Didn't match having
1232112327
error=0;

sql/sql_table.cc

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,11 +3196,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
31963196
{
31973197
column->length*= sql_field->charset->mbmaxlen;
31983198

3199-
if (key->type == Key::SPATIAL && column->length)
3199+
if (key->type == Key::SPATIAL)
32003200
{
3201-
my_error(ER_WRONG_SUB_KEY, MYF(0));
3202-
DBUG_RETURN(TRUE);
3203-
}
3201+
if (column->length)
3202+
{
3203+
my_error(ER_WRONG_SUB_KEY, MYF(0));
3204+
DBUG_RETURN(TRUE);
3205+
}
3206+
if (!f_is_geom(sql_field->pack_flag))
3207+
{
3208+
my_error(ER_SPATIAL_MUST_HAVE_GEOM_COL, MYF(0));
3209+
DBUG_RETURN(TRUE);
3210+
}
3211+
}
32043212

32053213
if (f_is_blob(sql_field->pack_flag) ||
32063214
(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,
32953303
}
32963304
}
32973305
}
3306+
// Catch invalid use of partial keys
32983307
else if (!f_is_geom(sql_field->pack_flag) &&
3299-
((column->length > length &&
3300-
!Field::type_can_have_key_part (sql_field->sql_type)) ||
3301-
((f_is_packed(sql_field->pack_flag) ||
3302-
((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
3303-
(key_info->flags & HA_NOSAME))) &&
3304-
column->length != length)))
3305-
{
3306-
/* Catch invalid uses of partial keys.
3307-
A key is identified as 'partial' if column->length != length.
3308-
A partial key is invalid if they data type does
3309-
not allow it, or the field is packed (as in MyISAM),
3310-
or the storage engine doesn't allow prefixed search and
3311-
the key is primary key.
3312-
*/
3313-
3308+
// is the key partial?
3309+
column->length != length &&
3310+
// is prefix length bigger than field length?
3311+
(column->length > length ||
3312+
// can the field have a partial key?
3313+
!Field::type_can_have_key_part (sql_field->sql_type) ||
3314+
// a packed field can't be used in a partial key
3315+
f_is_packed(sql_field->pack_flag) ||
3316+
// does the storage engine allow prefixed search?
3317+
((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
3318+
// and is this a 'unique' key?
3319+
(key_info->flags & HA_NOSAME))))
3320+
{
33143321
my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
33153322
DBUG_RETURN(TRUE);
33163323
}

0 commit comments

Comments
 (0)