[MDEV-29677] Wrong result with join query and innodb fulltext search Created: 2022-10-01  Updated: 2023-02-02

Status: Open
Project: MariaDB Server
Component/s: Full-text Search, Storage Engine - InnoDB
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.3

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 1
Labels: not-11.0-sel


 Description   

Testcase:

--source include/have_innodb.inc
  
CREATE TABLE t1 (a int) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1), (2);
CREATE TABLE t2 (a int, b2 char(10), FULLTEXT KEY b2 (b2)) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int) ENGINE = InnoDB;
INSERT INTO t3 VALUES (1,1), (2,1);
SELECT * FROM t2 where MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE);

set optimizer_switch='materialization=on';
EXPLAIN
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
 
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);

Produces a correct result:

id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    2       Using where
2       MATERIALIZED    t2      fulltext        b2      b2      0               1       Using where
2       MATERIALIZED    t3      ALL     NULL    NULL    NULL    NULL    2       Using where
...
count(*)
0

Note that this query plan executes the full text scan once.

Now, try a query plan executes the full text scan twice:

set optimizer_switch='materialization=off';
EXPLAIN
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
 
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);

Produces:

id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    2       Using where
2       DEPENDENT SUBQUERY      t2      fulltext        b2      b2      0               1       Using where
2       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    2       Using where
...
count(*)
1



 Comments   
Comment by Sergei Petrunia [ 2022-10-01 ]

bb-10.7-mdev29677

Comment by Sergei Petrunia [ 2022-10-01 ]

I used 10.7, didn't try earlier versions. Will need to do that.

Comment by Alice Sherepa [ 2022-11-30 ]

repeatable on the current 10.3 (4e9206736c403206915c09d)-10.10, not on bb-11.0 3135acf0bba521cd032cbf1

Generated at Thu Feb 08 10:10:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.