Bug #112377 Assert in AccessPath::index_merge()
Submitted: 18 Sep 2023 23:01 Modified: 19 Sep 2023 11:43
Reporter: Saumitr Pathak Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[18 Sep 2023 23:01] Saumitr Pathak
Description:
At the end of the file sql/range_optimizer/path_helpers.h, the dbug_dump() function has a couple of typos that look like copy-paste errors: 

    case AccessPath::INDEX_MERGE: {
      dbug_dump_index_merge(indent, verbose, *path->index_merge().children);
      break;
    }
    case AccessPath::ROWID_INTERSECTION:
      dbug_dump_rowid_intersection(indent, verbose,
                                   *path->index_merge().children);
      break;
    case AccessPath::ROWID_UNION:
      dbug_dump_rowid_union(indent, verbose, *path->index_merge().children);
      break;

If the DBUG tracing is enabled, then this can cause an assert in the AccessPath::index_merge() function as the following assert will fail: 

    assert(type == INDEX_MERGE);

How to repeat:
1. Enable DBUG tracing. 

2. Run an MTR test that exercises this code path. For example, "index_merge_rocksdb.test": 

https://github.com/facebook/mysql-5.6/blob/b4981a19b460837c8d191a9c7a6c8d692afdecbb/mysql-...

Suggested fix:
The fix is to fix the typos to point to the right helper functions: 

diff --git a/sql/range_optimizer/path_helpers.h b/sql/range_optimizer/path_helpers.h
index 391aafdad2b..da0faa27679 100644
--- a/sql/range_optimizer/path_helpers.h
+++ b/sql/range_optimizer/path_helpers.h
@@ -499,10 +499,10 @@ inline void dbug_dump(const AccessPath *path, int indent, bool verbose) {
     }
     case AccessPath::ROWID_INTERSECTION:
       dbug_dump_rowid_intersection(indent, verbose,
-                                   *path->index_merge().children);
+                                   *path->rowid_intersection().children);
       break;
     case AccessPath::ROWID_UNION:
-      dbug_dump_rowid_union(indent, verbose, *path->index_merge().children);
+      dbug_dump_rowid_union(indent, verbose, *path->rowid_union().children);
       break;
     case AccessPath::INDEX_SKIP_SCAN:
       dbug_dump_index_skip_scan(indent, verbose, path);
[19 Sep 2023 11:43] MySQL Verification Team
Hi Mr. Pathak,

Thank you for your bug report.

We have checked our code in 8.0.34 and latest 8.1 and the code is still the same.

Hence, you are correct. 

Thank you so much for your patch contribution.

Verified as reported.