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

Assertion `!(hint_forces_bnl && hint_forces_bka)' failed in check_join_cache_usage on SELECT w/ BNL() and BKA() hints

    XMLWordPrintable

Details

    Description

      Likely cause: commit 453a86f68e20b0f8e644d0febbce112985c601e0 (MDEV-36133), in check_join_cache_usage(). It is not a regression: CS 12.0.1, the first release with the BNL() and BKA() hints, has the commit.

      CREATE TABLE t1 (a INT);
      CREATE TABLE t2 (a INT, KEY (a));
      INSERT INTO t1 VALUES (1),(2),(3);
      INSERT INTO t2 VALUES (1),(2),(3);
      SELECT /*+ BNL() BKA(t2) */ COUNT(*) FROM t1 JOIN t2 ON t2.a = t1.a;
      DROP TABLE t1, t2;

      Leads to:

      CS 13.1.2 87e62ca17270e163a6d41b3fc8d6f4d440f1bb88 (Debug, Clang 22.1.8-20260622) Build 07/11/2026

      mariadbd: /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:15929: uint check_join_cache_usage(JOIN_TAB *, ulonglong, uint, uint, JOIN_TAB *): Assertion `!(hint_forces_bnl && hint_forces_bka)' failed.

      CS 13.1.2 87e62ca17270e163a6d41b3fc8d6f4d440f1bb88 (Debug, Clang 22.1.8-20260622) Build 07/11/2026

      Core was generated by `/tmp/optimizer-scan/MD071126-mariadb-13.1.2-linux-x86_64-dbg/bin/mariadbd --no-'.
      Program terminated with signal SIGABRT, Aborted.
      #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:44
       
      [Current thread is 1 (LWP 2942897)]
      (gdb) bt
      #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:44
      #1  __pthread_kill_internal (signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:78
      #2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6)at ./nptl/pthread_kill.c:89
      #3  0x000078403544527e in __GI_raise (sig=sig@entry=6)at ../sysdeps/posix/raise.c:26
      #4  0x00007840354288ff in __GI_abort () at ./stdlib/abort.c:79
      #5  0x000078403542881b in __assert_fail_base (fmt=0x7840355d1208 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5945d7cc09ce "!(hint_forces_bnl && hint_forces_bka)", file=file@entry=0x5945d7cbba29 "/tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc", line=line@entry=15929, function=function@entry=0x5945d7cc09f4 "uint check_join_cache_usage(JOIN_TAB *, ulonglong, uint, uint, JOIN_TAB *)") at ./assert/assert.c:96
      #6  0x000078403543b517 in __assert_fail (assertion=0x5945d7cc09ce "!(hint_forces_bnl && hint_forces_bka)", file=0x5945d7cbba29 "/tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc", line=15929, function=0x5945d7cc09f4 "uint check_join_cache_usage(JOIN_TAB *, ulonglong, uint, uint, JOIN_TAB *)") at ./assert/assert.c:105
      #7  0x00005945d6d36a6d in check_join_cache_usage (tab=0x703f000213c8, options=0, no_jbuf_after=2, table_index=1, prev_tab=0x703f00020f50)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:15929
      #8  0x00005945d6d367ac in check_join_cache_usage_for_tables (join=0x703f0001e0a0, options=0, no_jbuf_after=2)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:16255
      #9  0x00005945d6d19cef in make_join_readinfo (join=0x703f0001e0a0, options=0, no_jbuf_after=2) at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:16432
      #10 0x00005945d6d0cb07 in JOIN::optimize_stage2 (this=0x703f0001e0a0)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:3364
      #11 0x00005945d6d0b0af in JOIN::optimize_inner (this=0x703f0001e0a0)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:2790
      #12 0x00005945d6d08c86 in JOIN::optimize (this=0x703f0001e0a0)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:2017
      #13 0x00005945d6d014bd in mysql_select (thd=0x703f00000d60, tables=0x703f0001b670, fields=@0x703f0001b1c8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x703f0001b5e0, last = 0x703f0001b5e0, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2164525824, result=0x703f0001e070, unit=0x703f000052f8, select_lex=0x703f0001af10)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:5426
      #14 0x00005945d6d010bd in handle_select (thd=0x703f00000d60, lex=0x703f00005218, result=0x703f0001e070, setup_tables_done_option=0)at /tmp/optimizer-scan/13.1_dbg/sql/sql_select.cc:637
      #15 0x00005945d6ca6726 in execute_sqlcom_select (thd=0x703f00000d60, all_tables=0x703f0001b670)at /tmp/optimizer-scan/13.1_dbg/sql/sql_parse.cc:6216
      #16 0x00005945d6c9ca1b in mysql_execute_command (thd=0x703f00000d60, is_called_from_prepared_stmt=false)at /tmp/optimizer-scan/13.1_dbg/sql/sql_parse.cc:3989
      #17 0x00005945d6c95828 in mysql_parse (thd=0x703f00000d60, rawbuf=0x703f0001a4d0 "SELECT /*+ BNL() BKA(t2) */ COUNT(*) FROM t1 JOIN t2 ON t2.a = t1.a", length=67, parser_state=0x703ff70c69c0)at /tmp/optimizer-scan/13.1_dbg/sql/sql_parse.cc:7955
      #18 0x00005945d6c92fde in dispatch_command (command=COM_QUERY, thd=0x703f00000d60, packet=0x703f0000b701 "SELECT /*+ BNL() BKA(t2) */ COUNT(*) FROM t1 JOIN t2 ON t2.a = t1.a", packet_length=67, blocking=true)at /tmp/optimizer-scan/13.1_dbg/sql/sql_parse.cc:1903
      #19 0x00005945d6c962aa in do_command (thd=0x703f00000d60, blocking=true)at /tmp/optimizer-scan/13.1_dbg/sql/sql_parse.cc:1437
      #20 0x00005945d6e6e3fe in do_handle_one_connection (connect=0x5946179fd940, put_in_cache=true) at /tmp/optimizer-scan/13.1_dbg/sql/sql_connect.cc:1514
      #21 0x00005945d6e6e1e1 in handle_one_connection (arg=0x5946179e9f40)at /tmp/optimizer-scan/13.1_dbg/sql/sql_connect.cc:1426
      #22 0x000078403549cb84 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
      #23 0x0000784035529ecc in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

      /*+ BNL(t2) BKA(t2) */ with a LEFT JOIN gives the same assert. On optimized builds there is no assert. The CS 13.1.2 optimized build returns 3 for both queries.

      From the code it seems that check_join_cache_usage() in sql/sql_select.cc asserts that the BNL() and BKA() hints do not both apply to one table. The hint parser accepts both, at query block level as BNL() and for the table as BKA(t2), or both for the same table.

      Attachments

        Issue Links

          Activity

            People

              oleg.smirnov Oleg Smirnov
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  Remaining:
                  Time Spent - 1h Remaining Estimate - 3d
                  3d
                  Logged:
                  Time Spent - 1h Remaining Estimate - 3d
                  1h

                  Git Integration

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