mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 04:22:27 +01:00
2d8869d248
Several problems fixed : 1. Non constant expressions in UNION ... ORDER BY were not correctly cleaned up in st_select_lex_unit::cleanup() causing crashes in EXPLAIN EXTENDED because of fields quoted by these expressions pointing to the already freed temporary table used to calculate the UNION. Fixed by correctly cleaning up expressions of any depth. 2. Subqueries in the order by part of UNION ... ORDER BY ... caused a crash in EXPLAIN EXTENDED because of a transformation attempt made during EXPLAIN EXTENDED execution. Fixed by not doing the transformation when in EXPLAIN. 3. Fulltext functions caused crash when in the ORDER BY part of an un-parenthesized UNION that gets "promoted" to be valid for the whole union, e.g. SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY MATCHES (a) AGAINST ('abc' IN BOOLEAN MODE). This is a case that demonstrates a more general problem of parts of the query being moved to another level. When doing such transformation late in the optimization run when most of the flags about the contents of the query are already aggregated it's possible to "split" the flags so that they correctly reflect the new queries after the transformation. In specific the ST_SELECT_LEX::ftfunc_list is holding all the free text function for all the parts of the second SELECT in the UNION and we don't know what part of that is in the ORDER BY that we're to move to the UNION level and what part is about the other parts of the second SELECT. Fixed by throwing and error when such statements are about to be processed by adding a check for the presence of MATCH() inside the ORDER BY clause that's going to get promoted to UNION. To workaround this new limitation one must parenthesize the UNION SELECTs and provide a real global ORDER BY for the UNION outside of the parenthesis.
155 lines
5.3 KiB
Text
155 lines
5.3 KiB
Text
--disable_warnings
|
|
DROP TABLE IF EXISTS t1,t2,t3;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1 (
|
|
a INT AUTO_INCREMENT PRIMARY KEY,
|
|
message CHAR(20),
|
|
FULLTEXT(message)
|
|
) comment = 'original testcase by sroussey@network54.com';
|
|
INSERT INTO t1 (message) VALUES ("Testing"),("table"),("testbug"),
|
|
("steve"),("is"),("cool"),("steve is cool");
|
|
# basic MATCH
|
|
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve');
|
|
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve');
|
|
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE);
|
|
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE);
|
|
|
|
# MATCH + ORDER BY (with ft-ranges)
|
|
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY a;
|
|
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY a;
|
|
|
|
# MATCH + ORDER BY (with normal ranges) + UNIQUE
|
|
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE a in (2,7,4) and MATCH (message) AGAINST ('steve') ORDER BY a DESC;
|
|
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE a in (2,7,4) and MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY a DESC;
|
|
|
|
# MATCH + ORDER BY + UNIQUE (const_table)
|
|
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE a=7 and MATCH (message) AGAINST ('steve') ORDER BY 1;
|
|
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE a=7 and MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY 1;
|
|
|
|
# ORDER BY MATCH
|
|
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) as rel FROM t1 ORDER BY rel;
|
|
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel;
|
|
|
|
#
|
|
# BUG#6635 - test_if_skip_sort_order() thought it can skip filesort
|
|
# for fulltext searches too
|
|
#
|
|
alter table t1 add key m (message);
|
|
explain SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message;
|
|
SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message desc;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# reused boolean scan bug
|
|
#
|
|
CREATE TABLE t1 (
|
|
a INT AUTO_INCREMENT PRIMARY KEY,
|
|
message CHAR(20),
|
|
FULLTEXT(message)
|
|
);
|
|
INSERT INTO t1 (message) VALUES ("testbug"),("testbug foobar");
|
|
SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1;
|
|
SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel,a;
|
|
drop table t1;
|
|
|
|
# BUG#11869
|
|
CREATE TABLE t1 (
|
|
id int(11) NOT NULL auto_increment,
|
|
thread int(11) NOT NULL default '0',
|
|
beitrag longtext NOT NULL,
|
|
PRIMARY KEY (id),
|
|
KEY thread (thread),
|
|
FULLTEXT KEY beitrag (beitrag)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7923 ;
|
|
|
|
CREATE TABLE t2 (
|
|
id int(11) NOT NULL auto_increment,
|
|
text varchar(100) NOT NULL default '',
|
|
PRIMARY KEY (id),
|
|
KEY text (text)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;
|
|
|
|
CREATE TABLE t3 (
|
|
id int(11) NOT NULL auto_increment,
|
|
forum int(11) NOT NULL default '0',
|
|
betreff varchar(70) NOT NULL default '',
|
|
PRIMARY KEY (id),
|
|
KEY forum (forum),
|
|
FULLTEXT KEY betreff (betreff)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ;
|
|
|
|
--error ER_CANT_USE_OPTION_HERE
|
|
select a.text, b.id, b.betreff
|
|
from
|
|
t2 a inner join t3 b on a.id = b.forum inner join
|
|
t1 c on b.id = c.thread
|
|
where
|
|
match(b.betreff) against ('+abc' in boolean mode)
|
|
group by a.text, b.id, b.betreff
|
|
union
|
|
select a.text, b.id, b.betreff
|
|
from
|
|
t2 a inner join t3 b on a.id = b.forum inner join
|
|
t1 c on b.id = c.thread
|
|
where
|
|
match(c.beitrag) against ('+abc' in boolean mode)
|
|
group by
|
|
a.text, b.id, b.betreff
|
|
order by
|
|
match(b.betreff) against ('+abc' in boolean mode) desc;
|
|
|
|
--error ER_CANT_USE_OPTION_HERE
|
|
select a.text, b.id, b.betreff
|
|
from
|
|
t2 a inner join t3 b on a.id = b.forum inner join
|
|
t1 c on b.id = c.thread
|
|
where
|
|
match(b.betreff) against ('+abc' in boolean mode)
|
|
union
|
|
select a.text, b.id, b.betreff
|
|
from
|
|
t2 a inner join t3 b on a.id = b.forum inner join
|
|
t1 c on b.id = c.thread
|
|
where
|
|
match(c.beitrag) against ('+abc' in boolean mode)
|
|
order by
|
|
match(b.betreff) against ('+abc' in boolean mode) desc;
|
|
|
|
--error ER_CANT_USE_OPTION_HERE
|
|
select a.text, b.id, b.betreff
|
|
from
|
|
t2 a inner join t3 b on a.id = b.forum inner join
|
|
t1 c on b.id = c.thread
|
|
where
|
|
match(b.betreff) against ('+abc' in boolean mode)
|
|
union
|
|
select a.text, b.id, b.betreff
|
|
from
|
|
t2 a inner join t3 b on a.id = b.forum inner join
|
|
t1 c on b.id = c.thread
|
|
where
|
|
match(c.beitrag) against ('+abc' in boolean mode)
|
|
order by
|
|
match(betreff) against ('+abc' in boolean mode) desc;
|
|
|
|
# BUG#11869 part2: used table type doesn't support FULLTEXT indexes error
|
|
(select b.id, b.betreff from t3 b) union
|
|
(select b.id, b.betreff from t3 b)
|
|
order by match(betreff) against ('+abc' in boolean mode) desc;
|
|
|
|
--error 1191
|
|
(select b.id, b.betreff from t3 b) union
|
|
(select b.id, b.betreff from t3 b)
|
|
order by match(betreff) against ('+abc') desc;
|
|
|
|
select distinct b.id, b.betreff from t3 b
|
|
order by match(betreff) against ('+abc' in boolean mode) desc;
|
|
|
|
select b.id, b.betreff from t3 b group by b.id+1
|
|
order by match(betreff) against ('+abc' in boolean mode) desc;
|
|
|
|
drop table t1,t2,t3;
|
|
|
|
# End of 4.1 tests
|