MariaDB [test]> analyze format=json select SQL_NO_CACHE count(*) 
    -> FROM 
    ->   COMPLETED_TXN_COMPONENTS tc 
    ->   INNER JOIN 
    ->   (
    ->     SELECT 
    ->       CTC_DATABASE, CTC_TABLE, CTC_PARTITION, max(CTC_WRITEID) highestWriteId  
    ->     FROM COMPLETED_TXN_COMPONENTS
    ->     GROUP BY CTC_DATABASE, CTC_TABLE, CTC_PARTITION
    ->   ) c ON tc.CTC_DATABASE = c.CTC_DATABASE AND tc.CTC_TABLE = c.CTC_TABLE  AND 
    ->          (tc.CTC_PARTITION = c.CTC_PARTITION OR (tc.CTC_PARTITION IS NULL AND c.CTC_PARTITION IS NULL)) 
    ->   LEFT JOIN  
    ->   (
    ->     SELECT
    ->       CTC_DATABASE, CTC_TABLE, CTC_PARTITION, max(CTC_WRITEID) updateWriteId  
    ->     FROM COMPLETED_TXN_COMPONENTS  
    ->     WHERE 
    ->       CTC_UPDATE_DELETE = 'Y'   
    ->     GROUP BY CTC_DATABASE, CTC_TABLE, CTC_PARTITION 
    ->   ) c2 ON tc.CTC_DATABASE = c2.CTC_DATABASE AND tc.CTC_TABLE = c2.CTC_TABLE  AND 
    ->           (tc.CTC_PARTITION = c2.CTC_PARTITION OR (tc.CTC_PARTITION IS NULL AND c2.CTC_PARTITION IS NULL)
    ->   ) 
    -> WHERE 
    ->   tc.CTC_WRITEID < c.highestWriteId AND NOT tc.CTC_WRITEID <=> c2.updateWriteId;
| {
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 217261.723,
    "table": {
      "table_name": "tc",
      "access_type": "ALL",
      "possible_keys": ["COMPLETED_TXN_COMPONENTS_IDX"],
      "r_loops": 1,
      "rows": 136031,
      "r_rows": 141021,
      "r_table_time_ms": 56.995,
      "r_other_time_ms": 441.848,
      "r_engine_stats": {
        "pages_accessed": 934
      },
      "filtered": 100,
      "r_filtered": 100,
      "attached_condition": "tc.CTC_TABLE is not null"
    },
    "table": {
      "table_name": "<derived2>",
      "access_type": "ref",
      "possible_keys": ["key0"],
      "key": "key0",
      "key_length": "389",
      "used_key_parts": ["CTC_DATABASE", "CTC_TABLE"],
      "ref": ["test.tc.CTC_DATABASE", "test.tc.CTC_TABLE"],
      "r_loops": 141021,
      "rows": 2,
      "r_rows": 392.0611186,
      "r_table_time_ms": 14193.922,
      "r_other_time_ms": 20769.15,
      "filtered": 100,
      "r_filtered": 0.001721866,
      "attached_condition": "tc.CTC_WRITEID < c.highestWriteId and (c.CTC_PARTITION = tc.CTC_PARTITION or tc.CTC_PARTITION is null and c.CTC_PARTITION is null)",
      "materialized": {
        "lateral": 1,
        "query_block": {
          "select_id": 2,
          "r_loops": 141021,
          "r_total_time_ms": 207419.818,
          "outer_ref_condition": "tc.CTC_TABLE is not null",
          "filesort": {
            "sort_key": "COMPLETED_TXN_COMPONENTS.CTC_PARTITION",
            "r_loops": 141021,
            "r_total_time_ms": 16094.534,
            "r_used_priority_queue": false,
            "r_output_rows": 392,
            "r_buffer_size": "(varied across executions)",
            "r_sort_mode": "packed_sort_key,rowid",
            "temporary_table": {
              "table": {
                "table_name": "COMPLETED_TXN_COMPONENTS",
                "access_type": "ref",
                "possible_keys": ["COMPLETED_TXN_COMPONENTS_IDX"],
                "key": "COMPLETED_TXN_COMPONENTS_IDX",
                "key_length": "389",
                "used_key_parts": ["CTC_DATABASE", "CTC_TABLE"],
                "ref": ["test.tc.CTC_DATABASE", "test.tc.CTC_TABLE"],
                "r_loops": 141021,
                "rows": 1,
                "r_rows": 397.1914892,
                "r_table_time_ms": 53947.73,
                "r_other_time_ms": 110475.882,
                "r_engine_stats": {
                  "pages_accessed": 112953315
                },
                "filtered": 100,
                "r_filtered": 100,
                "attached_condition": "COMPLETED_TXN_COMPONENTS.CTC_DATABASE <=> tc.CTC_DATABASE and COMPLETED_TXN_COMPONENTS.CTC_TABLE <=> tc.CTC_TABLE"
              }
            }
          }
        }
      }
    },
    "table": {
      "table_name": "<derived3>",
      "access_type": "ref",
      "possible_keys": ["key0"],
      "key": "key0",
      "key_length": "390",
      "used_key_parts": ["CTC_DATABASE", "CTC_TABLE"],
      "ref": ["test.tc.CTC_DATABASE", "test.tc.CTC_TABLE"],
      "r_loops": 952,
      "rows": 10,
      "r_rows": 248.8413866,
      "r_table_time_ms": 5.836,
      "r_other_time_ms": 687.358,
      "filtered": 100,
      "r_filtered": 0.401862413,
      "attached_condition": "trigcond(!(tc.CTC_WRITEID <=> c2.updateWriteId)) and trigcond((c2.CTC_PARTITION = tc.CTC_PARTITION or tc.CTC_PARTITION is null and c2.CTC_PARTITION is null) and trigcond(tc.CTC_TABLE is not null))",
      "materialized": {
        "query_block": {
          "select_id": 3,
          "r_loops": 1,
          "r_total_time_ms": 1018.324,
          "filesort": {
            "sort_key": "COMPLETED_TXN_COMPONENTS.CTC_DATABASE, COMPLETED_TXN_COMPONENTS.CTC_TABLE, COMPLETED_TXN_COMPONENTS.CTC_PARTITION",
            "r_loops": 1,
            "r_total_time_ms": 68.583,
            "r_used_priority_queue": false,
            "r_output_rows": 100380,
            "r_sort_passes": 1,
            "r_buffer_size": "2047Kb",
            "r_sort_mode": "packed_sort_key,rowid",
            "temporary_table": {
              "table": {
                "table_name": "COMPLETED_TXN_COMPONENTS",
                "access_type": "ALL",
                "possible_keys": ["COMPLETED_TXN_COMPONENTS_IDX"],
                "r_loops": 1,
                "rows": 136031,
                "r_rows": 141021,
                "r_table_time_ms": 32.533,
                "r_other_time_ms": 223.917,
                "r_engine_stats": {
                  "pages_accessed": 934
                },
                "filtered": 100,
                "r_filtered": 71.18088795,
                "attached_condition": "COMPLETED_TXN_COMPONENTS.CTC_UPDATE_DELETE = 'Y'"
              }
            }
          }
        }
      }
    }
  }
} |
1 row in set (3 min 37.263 sec)

MariaDB [test]> 
