[MDEV-21426] Distinct on a fulltext indexed column not working Created: 2020-01-06  Updated: 2020-01-07  Resolved: 2020-01-07

Status: Closed
Project: MariaDB Server
Component/s: Full-text Search
Affects Version/s: 10.0, 10.1, 10.4.10, 10.2, 10.3, 10.4
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Maikel Punie Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-9232 Fulltext index on a given column caus... Confirmed

 Description   

we want to return all unique values from a column (using distinct), the column has a fulltext index defined.
In this case a simple select does not return any values, removing the DISTINCT or the fulltext index solves the problem.

MariaDB [regressiondb]> SELECT DISTINCT tagResult AS name FROM regressRun_tagResult WHERE tagResult LIKE 'esm_202-start_18677%';
Empty set (0.00 sec)
 
MariaDB [regressiondb]> SELECT tagResult AS name FROM regressRun_tagResult WHERE tagResult LIKE 'esm_202-start_18677%' ORDER BY tagResult;
+----------------------------------------------+
| name                                         |
+----------------------------------------------+
| esm_202-start_18677#date=2019/12/18_16:48:24 |
+----------------------------------------------+
1 row in set (0.15 sec)
 
MariaDB [regressiondb]> show create table regressRun_tagResult;
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table                | Create Table                                                                                                                                                                                                                                                                               |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| regressRun_tagResult | CREATE TABLE `regressRun_tagResult` (
  `regressRun_id` int(11) unsigned NOT NULL,
  `tagResult` varchar(255) COLLATE latin1_bin NOT NULL,
  PRIMARY KEY (`regressRun_id`,`tagResult`),
  FULLTEXT KEY `tagResult` (`tagResult`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [regressiondb]> alter table regressRun_tagResult drop index tagResult;
Query OK, 0 rows affected (3.98 sec)
Records: 0  Duplicates: 0  Warnings: 0
 
MariaDB [regressiondb]> SELECT DISTINCT tagResult AS name FROM regressRun_tagResult WHERE tagResult LIKE 'esm_202-start_18677%';
+----------------------------------------------+
| name                                         |
+----------------------------------------------+
| esm_202-start_18677#date=2019/12/18_16:48:24 |
+----------------------------------------------+
1 row in set (0.11 sec)
 
MariaDB [regressiondb]> SELECT tagResult AS name FROM regressRun_tagResult WHERE tagResult LIKE 'esm_202-start_18677%' ORDER BY tagResult;
+----------------------------------------------+
| name                                         |
+----------------------------------------------+
| esm_202-start_18677#date=2019/12/18_16:48:24 |
+----------------------------------------------+
1 row in set (0.16 sec)



 Comments   
Comment by Alice Sherepa [ 2020-01-07 ]

Thanks for the report! Repeatable on 10.0-10.4, with InnoDB:

--source include/have_innodb.inc
 
CREATE TABLE t1 ( id int NOT NULL, nm varchar(255), PRIMARY KEY (id,nm), FULLTEXT KEY nm (nm)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, "esm_202-start_18677#date=2019/12/18_16:48:24"), (2, "esm_202-start_18677#date=2019/12/18_16:48:24"), (3, "esm_202-start_18677#date=2019/12/18_16:48:24"), (4, "esm_202-start_18677#date=2019/12/18_16:48:24"), (5, "esm_202-start_18677#date=2019/12/18_16:48:24");
 
SELECT nm FROM t1 WHERE nm LIKE 'esm_202-start_18677%';
SELECT DISTINCT nm FROM t1 WHERE nm LIKE 'esm_202-start_18677%';
SELECT DISTINCT (ucase(nm)) FROM t1 WHERE nm LIKE 'esm_202-start_18677%';

MariaDB [test]> SELECT nm FROM t1 WHERE nm LIKE 'esm_202-start_18677%';
+----------------------------------------------+
| nm                                           |
+----------------------------------------------+
| esm_202-start_18677#date=2019/12/18_16:48:24 |
| esm_202-start_18677#date=2019/12/18_16:48:24 |
| esm_202-start_18677#date=2019/12/18_16:48:24 |
| esm_202-start_18677#date=2019/12/18_16:48:24 |
| esm_202-start_18677#date=2019/12/18_16:48:24 |
+----------------------------------------------+
5 rows in set (0.000 sec)
 
MariaDB [test]> SELECT DISTINCT nm FROM t1 WHERE nm LIKE 'esm_202-start_18677%';
Empty set (0.000 sec)
 
MariaDB [test]> SELECT DISTINCT (ucase(nm)) FROM t1 WHERE nm LIKE 'esm_202-start_18677%';
+----------------------------------------------+
| (ucase(nm))                                  |
+----------------------------------------------+
| ESM_202-START_18677#DATE=2019/12/18_16:48:24 |
+----------------------------------------------+
1 row in set (0.001 sec)
MariaDB [test]> SELECT DISTINCT nm FROM t1 force index (primary) WHERE nm LIKE 'esm_202-start_18677%';
+----------------------------------------------+
| nm                                           |
+----------------------------------------------+
| esm_202-start_18677#date=2019/12/18_16:48:24 |
+----------------------------------------------+
1 row in set (0.000 sec)

Generated at Thu Feb 08 09:07:03 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.