Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-29778

Having Unique index interference with MATCH from a FULLTEXT

Details

    Description

      We waned to use the score of the MATCH function on a FULLTEXT index to show relevance of the result.
      For one of the column/tables we didn't get a score event with a full match.
      After further investigation we discovered that if we have an UNIQUE INDEX on the same column on an InnoDB table the MATCH stops working.
      Here is a simple script to reproduce (also attached)

      CREATE TABLE IF NOT EXISTS ft_test(copy VARCHAR(255),FULLTEXT(copy));
       
      INSERT INTO ft_test(copy) VALUES ('test');
       
      SELECT copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test;
       
      ALTER TABLE ft_test ADD UNIQUE INDEX ft_test_unq (copy) USING BTREE;
       
      SELECT copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test;
      

      The first select would produce correct result as:

      +------+----------------------------+
      | copy | rel                        |
      +------+----------------------------+
      | test | 0.000000001885928302414186 |
      +------+----------------------------+
      
      

      Where as the second would return:

      +------+------+
      | copy | rel  |
      +------+------+
      | test |    0 |
      +------+------+
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Thank you for the report!
            I repeated as described on 10.3-10.10.
            As a temporary workaround one could use index hints and after that further select returned correct result.

            MariaDB [test]> CREATE or replace TABLE ft_test(copy VARCHAR(255),FULLTEXT(copy), UNIQUE INDEX ft_test_unq (copy) USING BTREE) engine=innodb;
            Query OK, 0 rows affected (0,159 sec)
             
            MariaDB [test]> INSERT INTO ft_test(copy) VALUES ('test');
            Query OK, 1 row affected (0,009 sec)
             
            MariaDB [test]> SELECT sql_no_cache copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test;
            +------+------+
            | copy | rel  |
            +------+------+
            | test |    0 |
            +------+------+
            1 row in set (0,001 sec)
             
            MariaDB [test]> show create table ft_test;
            +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
            | Table   | Create Table                                                                                                                                                                        |
            +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
            | ft_test | CREATE TABLE `ft_test` (
              `copy` varchar(255) DEFAULT NULL,
              UNIQUE KEY `ft_test_unq` (`copy`) USING BTREE,
              FULLTEXT KEY `copy` (`copy`)
            ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
            +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
            1 row in set (0,001 sec)
             
            MariaDB [test]> SELECT sql_no_cache copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test ignore index (ft_test_unq);
            +------+----------------------------+
            | copy | rel                        |
            +------+----------------------------+
            | test | 0.000000001885928302414186 |
            +------+----------------------------+
            1 row in set (0,001 sec)
             
            MariaDB [test]> SELECT sql_no_cache copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test;
            +------+----------------------------+
            | copy | rel                        |
            +------+----------------------------+
            | test | 0.000000001885928302414186 |
            +------+----------------------------+
            1 row in set (0,001 sec)
            

            alice Alice Sherepa added a comment - Thank you for the report! I repeated as described on 10.3-10.10. As a temporary workaround one could use index hints and after that further select returned correct result. MariaDB [test]> CREATE or replace TABLE ft_test(copy VARCHAR(255),FULLTEXT(copy), UNIQUE INDEX ft_test_unq (copy) USING BTREE) engine=innodb; Query OK, 0 rows affected (0,159 sec)   MariaDB [test]> INSERT INTO ft_test(copy) VALUES ('test'); Query OK, 1 row affected (0,009 sec)   MariaDB [test]> SELECT sql_no_cache copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test; +------+------+ | copy | rel | +------+------+ | test | 0 | +------+------+ 1 row in set (0,001 sec)   MariaDB [test]> show create table ft_test; +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ft_test | CREATE TABLE `ft_test` ( `copy` varchar(255) DEFAULT NULL, UNIQUE KEY `ft_test_unq` (`copy`) USING BTREE, FULLTEXT KEY `copy` (`copy`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0,001 sec)   MariaDB [test]> SELECT sql_no_cache copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test ignore index (ft_test_unq); +------+----------------------------+ | copy | rel | +------+----------------------------+ | test | 0.000000001885928302414186 | +------+----------------------------+ 1 row in set (0,001 sec)   MariaDB [test]> SELECT sql_no_cache copy,MATCH(copy) AGAINST('test' IN BOOLEAN MODE) rel FROM ft_test; +------+----------------------------+ | copy | rel | +------+----------------------------+ | test | 0.000000001885928302414186 | +------+----------------------------+ 1 row in set (0,001 sec)

            OK to push.

            marko Marko Mäkelä added a comment - OK to push.

            People

              thiru Thirunarayanan Balathandayuthapani
              lukav Anton Avramov
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.