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

NO_INDEX hint using QB_NAME doesn't work inside VIEWs

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 13.0
    • 12.2
    • Optimizer
    • Q2/2026 Server Maintenance

    Description

      Looking at latest tree, tip cset

      commit e984af48c2920f77ccd19de6a623e7725401ddb1 (HEAD)
      Author: Oleg Smirnov <olernov@gmail.com>
      Date:   Tue Apr 14 00:38:45 2026 +0700
       
          MDEV-39304 QB_Name hint with path is silently ignored inside view definition
      

      create table t1 (
       a int,
       b int,
       index(a),
       index(b)
      );
      insert into t1 select seq from seq_1_to_10000;
      

      A query that uses an index:

      explain 
      select  a,b from t1 where a<3 limit 10 ;
      +------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
      | id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                 |
      +------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
      |    1 | SIMPLE      | t1    | range | a             | a    | 5       | NULL | 4    | Using index condition |
      +------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
      

      Disable index with NO_INDEX hint:

      explain 
      select /*+ QB_NAME(foo) NO_INDEX(t1@foo) */ a,b from t1 where a<3 limit 10 ;
      +------+-------------+-------+------+---------------+------+---------+------+-------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+-------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 10157 | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+-------+-------------+
      

      Wrap this in a view:

      create view v20 as 
      select /*+ QB_NAME(foo) NO_INDEX(t1@foo) */ a,b from t1 where a<3 limit 10 ;
      

      explain select * from v20;
      +------+-------------+------------+-------+---------------+------+---------+------+------+-----------------------+
      | id   | select_type | table      | type  | possible_keys | key  | key_len | ref  | rows | Extra                 |
      +------+-------------+------------+-------+---------------+------+---------+------+------+-----------------------+
      |    1 | PRIMARY     | <derived2> | ALL   | NULL          | NULL | NULL    | NULL | 4    |                       |
      |    2 | DERIVED     | t1         | range | a             | a    | 5       | NULL | 4    | Using index condition |
      +------+-------------+------------+-------+---------------+------+---------+------+------+-----------------------+
      

      The hint seems to be ignored?
      SHOW CREATE VIEW shows QB_NAME hint but not NO_INDEX hint:

      show create view v20\G
      *************************** 1. row ***************************
                      View: v20
               Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v20` AS select /*+ QB_NAME(`foo`) */ `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` < 3 limit 10
      character_set_client: utf8mb3
      collation_connection: utf8mb3_uca1400_ai_ci
      1 row in set (0.001 sec)
      

      Note that if I use NO_INDEX to address table t1 directly, without QB_NAME, then it works:

      MariaDB [test]> create view v21 as select /*+ NO_INDEX(t1) */ a,b from t1 where a<3 limit 10 ;
      Query OK, 0 rows affected (0.013 sec)
      

      MariaDB [test]> show create view v21\G
      *************************** 1. row ***************************
                      View: v21
               Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v21` AS select /*+ NO_INDEX(`t1`) */ `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`a` < 3 limit 10
      character_set_client: utf8mb3
      collation_connection: utf8mb3_uca1400_ai_ci
      1 row in set (0.001 sec)
      

      MariaDB [test]> explain select * from v21;
      +------+-------------+------------+------+---------------+------+---------+------+-------+-------------+
      | id   | select_type | table      | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
      +------+-------------+------------+------+---------------+------+---------+------+-------+-------------+
      |    1 | PRIMARY     | <derived2> | ALL  | NULL          | NULL | NULL    | NULL | 10    |             |
      |    2 | DERIVED     | t1         | ALL  | NULL          | NULL | NULL    | NULL | 10157 | Using where |
      +------+-------------+------------+------+---------------+------+---------+------+-------+-------------+
      

      Attachments

        Issue Links

          Activity

            People

              oleg.smirnov Oleg Smirnov
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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