|
thanks for the test case.
$ podman exec -t test mariadb -u test -ptest test -e "select version();analyze format=json SELECT count(open.id) as open, count(closed.id) as closed FROM test t LEFT JOIN test open ON (open.id=t.id AND open.status='open') LEFT JOIN test closed ON (closed.id=t.id AND closed.status='closed')\\G"
|
+---------------------------------------+
|
| version() |
|
+---------------------------------------+
|
| 11.0.2-MariaDB-1:11.0.2+maria~ubu2204 |
|
+---------------------------------------+
|
*************************** 1. row ***************************
|
ANALYZE: {
|
"query_optimization": {
|
"r_total_time_ms": 0.120357252
|
},
|
"query_block": {
|
"select_id": 1,
|
"cost": 34.96745253,
|
"r_loops": 1,
|
"r_total_time_ms": 50.61856297,
|
"const_condition": "1",
|
"nested_loop": [
|
{
|
"table": {
|
"table_name": "t",
|
"access_type": "index",
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"loops": 1,
|
"r_loops": 1,
|
"rows": 44100,
|
"r_rows": 44100,
|
"cost": 6.141240342,
|
"r_table_time_ms": 2.271114788,
|
"r_other_time_ms": 1.784361469,
|
"filtered": 100,
|
"r_filtered": 100,
|
"using_index": true
|
}
|
},
|
{
|
"table": {
|
"table_name": "open",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "status"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.t.id"],
|
"rowid_filter": {
|
"range": {
|
"key": "status",
|
"used_key_parts": ["status"]
|
},
|
"rows": 3,
|
"selectivity_pct": 0.006802721,
|
"r_rows": 3,
|
"r_lookups": 44100,
|
"r_selectivity_pct": 0.006802721,
|
"r_buffer_size": 2,
|
"r_filling_time_ms": 0.00300845
|
},
|
"loops": 44100,
|
"r_loops": 44100,
|
"rows": 1,
|
"r_rows": 6.802721e-5,
|
"cost": 28.82041071,
|
"r_table_time_ms": 16.61129226,
|
"r_other_time_ms": 1.967738371,
|
"filtered": 0.006802721,
|
"r_filtered": 100,
|
"attached_condition": "trigcond(`open`.`status` = 'open')"
|
}
|
},
|
{
|
"table": {
|
"table_name": "closed",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "status"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.t.id"],
|
"loops": 3,
|
"r_loops": 44100,
|
"rows": 1,
|
"r_rows": 1,
|
"cost": 0.005801478,
|
"r_table_time_ms": 23.55952462,
|
"r_other_time_ms": 4.42011174,
|
"filtered": 99.97052002,
|
"r_filtered": 99.99319728,
|
"attached_condition": "trigcond(closed.`status` = 'closed')"
|
}
|
}
|
]
|
}
|
}
|
|
10.6.14
|
+-----------------------------------------+
|
| version() |
|
+-----------------------------------------+
|
| 10.6.14-MariaDB-1:10.6.14+maria~ubu2004 |
|
+-----------------------------------------+
|
*************************** 1. row ***************************
|
ANALYZE: {
|
"query_block": {
|
"select_id": 1,
|
"r_loops": 1,
|
"r_total_time_ms": 78908.18444,
|
"const_condition": "1",
|
"table": {
|
"table_name": "t",
|
"access_type": "index",
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"r_loops": 1,
|
"rows": 44100,
|
"r_rows": 44100,
|
"r_table_time_ms": 2.580078919,
|
"r_other_time_ms": 2.097937098,
|
"filtered": 100,
|
"r_filtered": 100,
|
"using_index": true
|
},
|
"table": {
|
"table_name": "open",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "status"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.t.id"],
|
"rowid_filter": {
|
"range": {
|
"key": "status",
|
"used_key_parts": ["status"]
|
},
|
"rows": 3,
|
"selectivity_pct": 0.006802721,
|
"r_rows": 3,
|
"r_lookups": 44100,
|
"r_selectivity_pct": 0.006802721,
|
"r_buffer_size": 2,
|
"r_filling_time_ms": 0.002808746
|
},
|
"r_loops": 44100,
|
"rows": 1,
|
"r_rows": 6.802721e-5,
|
"r_table_time_ms": 19.31780521,
|
"r_other_time_ms": 2.676132408,
|
"filtered": 0.006802721,
|
"r_filtered": 100,
|
"attached_condition": "trigcond(`open`.`status` = 'open')"
|
},
|
"block-nl-join": {
|
"table": {
|
"table_name": "closed",
|
"access_type": "ALL",
|
"possible_keys": ["PRIMARY", "status"],
|
"r_loops": 2,
|
"rows": 44100,
|
"r_rows": 44100,
|
"r_table_time_ms": 14.6934785,
|
"r_other_time_ms": 4.41740098,
|
"filtered": 99.97052002,
|
"r_filtered": 99.99319728,
|
"attached_condition": "closed.`status` = 'closed'"
|
},
|
"buffer_type": "flat",
|
"buffer_size": "256Kb",
|
"join_type": "BNL",
|
"attached_condition": "trigcond(closed.`id` = t.`id` and closed.`status` = 'closed')",
|
"r_loops": 44100,
|
"r_filtered": 0.002267728,
|
"r_unpack_time_ms": 35048.6041,
|
"r_other_time_ms": 43813.79331,
|
"r_effective_rows": 44097
|
}
|
}
|
}
|
Also tested affected versions.
10.3/5.5 is quick:
+-----------------------------------------+
|
| version() |
|
+-----------------------------------------+
|
| 10.3.39-MariaDB-1:10.3.39+maria~ubu2004 |
|
+-----------------------------------------+
|
*************************** 1. row ***************************
|
EXPLAIN: {
|
"query_block": {
|
"select_id": 1,
|
"const_condition": "1",
|
"table": {
|
"table_name": "t",
|
"access_type": "index",
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"rows": 44100,
|
"filtered": 100,
|
"using_index": true
|
},
|
"table": {
|
"table_name": "open",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "status"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.t.id"],
|
"rows": 1,
|
"filtered": 100,
|
"attached_condition": "trigcond(`open`.`status` = 'open')"
|
},
|
"table": {
|
"table_name": "closed",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "status"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.t.id"],
|
"rows": 1,
|
"filtered": 100,
|
"attached_condition": "trigcond(closed.`status` = 'closed')"
|
}
|
}
|
}
|
|