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

Possible problem with ha_innobase::build_template

Details

    Description

      While working on MDEV-27366 a potentially problematic piece of code was found in /storage/innobase/handler/ha_innodb.cc:

                   if ((active_index != MAX_KEY
      	            && active_index == pushed_idx_cond_keyno)
      	            || (pushed_rowid_filter && rowid_filter_is_active)) {
      		       /* Push down an index condition or an end_range check. */
              ...
      		if (active_index == pushed_idx_cond_keyno) {
      			m_prebuilt->idx_cond = this;
      		}
      	}
      

      The last condition satisfies when

      active_index == pushed_idx_cond_keyno == MAX_KEY

      which doesn't look correct. After fixing MDEV-27366 there is no test case to reproduce this scenario.

      Attachments

        Issue Links

          Activity

            oleg.smirnov Oleg Smirnov created issue -
            oleg.smirnov Oleg Smirnov made changes -
            Field Original Value New Value
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            oleg.smirnov Oleg Smirnov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            oleg.smirnov Oleg Smirnov made changes -
            Description While working on MDEV-27366 a potentially problematic piece of code was found in /storage/innobase/handler/ha_innodb.cc:
            {code}
            if (active_index == pushed_idx_cond_keyno) {
            m_prebuilt->idx_cond = this;
            }
            {code}

            This condition satisfies when {code}active_index == pushed_idx_cond_keyno == MAX_KEY{code} which doesn't look correct. After fixing MDEV-27366 there is no test case to reproduce this scenario.
            While working on MDEV-27366 a potentially problematic piece of code was found in /storage/innobase/handler/ha_innodb.cc:
            {code}
                         if ((active_index != MAX_KEY
            && active_index == pushed_idx_cond_keyno)

            || (pushed_rowid_filter && rowid_filter_is_active)) {

            /* Push down an index condition or an end_range check. */

                    ...

            if (active_index == pushed_idx_cond_keyno) {

            m_prebuilt->idx_cond = this;

            }

            }

            {code}

            This condition satisfies when {code}active_index == pushed_idx_cond_keyno == MAX_KEY{code} which doesn't look correct. After fixing MDEV-27366 there is no test case to reproduce this scenario.
            oleg.smirnov Oleg Smirnov made changes -
            Description While working on MDEV-27366 a potentially problematic piece of code was found in /storage/innobase/handler/ha_innodb.cc:
            {code}
                         if ((active_index != MAX_KEY
            && active_index == pushed_idx_cond_keyno)

            || (pushed_rowid_filter && rowid_filter_is_active)) {

            /* Push down an index condition or an end_range check. */

                    ...

            if (active_index == pushed_idx_cond_keyno) {

            m_prebuilt->idx_cond = this;

            }

            }

            {code}

            This condition satisfies when {code}active_index == pushed_idx_cond_keyno == MAX_KEY{code} which doesn't look correct. After fixing MDEV-27366 there is no test case to reproduce this scenario.
            While working on MDEV-27366 a potentially problematic piece of code was found in /storage/innobase/handler/ha_innodb.cc:
            {code}
                         if ((active_index != MAX_KEY
            && active_index == pushed_idx_cond_keyno)
            || (pushed_rowid_filter && rowid_filter_is_active)) {
            /* Push down an index condition or an end_range check. */
                    ...
            if (active_index == pushed_idx_cond_keyno) {
            m_prebuilt->idx_cond = this;
            }
            }
            {code}

            The last condition satisfies when {code}active_index == pushed_idx_cond_keyno == MAX_KEY{code} which doesn't look correct. After fixing MDEV-27366 there is no test case to reproduce this scenario.
            oleg.smirnov Oleg Smirnov made changes -
            Assignee Oleg Smirnov [ JIRAUSER50405 ] Marko Mäkelä [ marko ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            oleg.smirnov Oleg Smirnov added a comment -

            marko, could you please review the branch bb-10.4-MDEV-28747?

            oleg.smirnov Oleg Smirnov added a comment - marko , could you please review the branch bb-10.4- MDEV-28747 ?
            Roel Roel Van de Paar made changes -

            The commit message should mention both MDEVs.

            Could the assignment be moved at the start of the outer if block? It would be easier to follow the logic in that way? Even a goto could be helpful for both the human reader and the processor:

            	if (active_index != MAX_KEY
            	    && active_index == pushed_idx_cond_keyno) {
            		m_prebuilt->idx_cond = this;
            		goto icp;
            	} else if (pushed_rowid_filter && rowid_filter_is_active) {
            icp:
            		/* Push down an index condition or an end_range check. */
            		for (ulint i = 0; i < n_fields; i++) {
            

            I think that it could be useful to check what would happen if the change that was mentioned in MDEV-16402 were reverted.

            marko Marko Mäkelä added a comment - The commit message should mention both MDEVs. Could the assignment be moved at the start of the outer if block? It would be easier to follow the logic in that way? Even a goto could be helpful for both the human reader and the processor: if (active_index != MAX_KEY && active_index == pushed_idx_cond_keyno) { m_prebuilt->idx_cond = this ; goto icp; } else if (pushed_rowid_filter && rowid_filter_is_active) { icp: /* Push down an index condition or an end_range check. */ for (ulint i = 0; i < n_fields; i++) { I think that it could be useful to check what would happen if the change that was mentioned in MDEV-16402 were reverted.
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ] Oleg Smirnov [ JIRAUSER50405 ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            oleg.smirnov Oleg Smirnov added a comment -

            Agree, fixed the first two comments and force-pushed.

            Regarding the 3rd point: commenting out the restriction mentioned:

            sql/opt_index_pushdown.cc

              if ((tab->table->file->index_flags(keyno, 0, 1) &
                  HA_DO_INDEX_COND_PUSHDOWN) &&
                 optimizer_flag(tab->join->thd, OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN) &&
                 tab->join->thd->lex->sql_command != SQLCOM_UPDATE_MULTI &&
                 tab->join->thd->lex->sql_command != SQLCOM_DELETE_MULTI &&
                 tab->type != JT_CONST && tab->type != JT_SYSTEM 
            /*&&
                 !(keyno == tab->table->s->primary_key &&             // (6)
                   tab->table->file->primary_key_is_clustered())*/
            )     // (6)
            

            causes 9 tests from the main suite fail due to updated execution plans, but no crashes or unexpected results returned are observed.
            I tried to analyze performance impact using sysbench (https://github.com/akopytov/sysbench) but couldn't make it work easily. For some reason it doesn't see MariaDB server running. Should I try to get sysbench working or there are other ways we can measure performance impact?

            oleg.smirnov Oleg Smirnov added a comment - Agree, fixed the first two comments and force-pushed. Regarding the 3rd point: commenting out the restriction mentioned: sql/opt_index_pushdown.cc if ((tab->table->file->index_flags(keyno, 0, 1) & HA_DO_INDEX_COND_PUSHDOWN) && optimizer_flag(tab->join->thd, OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN) && tab->join->thd->lex->sql_command != SQLCOM_UPDATE_MULTI && tab->join->thd->lex->sql_command != SQLCOM_DELETE_MULTI && tab->type != JT_CONST && tab->type != JT_SYSTEM /*&& !(keyno == tab->table->s->primary_key && // (6) tab->table->file->primary_key_is_clustered())*/ ) // (6) causes 9 tests from the main suite fail due to updated execution plans, but no crashes or unexpected results returned are observed. I tried to analyze performance impact using sysbench ( https://github.com/akopytov/sysbench ) but couldn't make it work easily. For some reason it doesn't see MariaDB server running. Should I try to get sysbench working or there are other ways we can measure performance impact?

            oleg.smirnov, thank you for revising the fix. It should be OK to push if all tests pass.

            Thank you for testing also MDEV-16402. Let us continue the discussion in that ticket.

            marko Marko Mäkelä added a comment - oleg.smirnov , thank you for revising the fix. It should be OK to push if all tests pass. Thank you for testing also MDEV-16402 . Let us continue the discussion in that ticket.
            oleg.smirnov Oleg Smirnov added a comment -

            Pushed commit 5efadf8d8c6076bbee73e45afe050ab62c517f3c to 10.4

            oleg.smirnov Oleg Smirnov added a comment - Pushed commit 5efadf8d8c6076bbee73e45afe050ab62c517f3c to 10.4
            oleg.smirnov Oleg Smirnov made changes -
            Component/s Storage Engine - InnoDB [ 10129 ]
            Fix Version/s 10.4.26 [ 27511 ]
            Fix Version/s 10.5.17 [ 27509 ]
            Fix Version/s 10.6.9 [ 27507 ]
            Fix Version/s 10.7.5 [ 27505 ]
            Fix Version/s 10.8.4 [ 27503 ]
            Fix Version/s 10.9.2 [ 27115 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]

            People

              oleg.smirnov Oleg Smirnov
              oleg.smirnov Oleg Smirnov
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.