Skip to content

Commit 7498978

Browse files
committed
MDEV-27699 ANALYZE FORMAT=JSON fields are incorrect for UNION ALL queries
UNION ALL queries are a subject of optimization introduced in MDEV-334 when creation of a temporary table is skipped. While there is a check for this optimization in Explain_union::print_explain() there was no such in Explain_union::print_explain_json(). This resulted in printing irrelevant data like: "union_result": { "table_name": "<union2,3>", "access_type": "ALL", "r_loops": 0, "r_rows": null in case when creation of the temporary table was actually optimized out. This commits adds a check whether the temporary table was actually created during the UNION ALL processing and eliminates printing of the irrelevant data.
1 parent 83516a3 commit 7498978

File tree

6 files changed

+20
-78
lines changed

6 files changed

+20
-78
lines changed

mysql-test/main/cte_recursive.result

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,10 +4050,6 @@ ANALYZE
40504050
{
40514051
"query_block": {
40524052
"union_result": {
4053-
"table_name": "<union1,4>",
4054-
"access_type": "ALL",
4055-
"r_loops": 0,
4056-
"r_rows": null,
40574053
"query_specifications": [
40584054
{
40594055
"query_block": {

mysql-test/main/derived_cond_pushdown.result

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10742,8 +10742,6 @@ EXPLAIN
1074210742
"materialized": {
1074310743
"query_block": {
1074410744
"union_result": {
10745-
"table_name": "<union2,3>",
10746-
"access_type": "ALL",
1074710745
"query_specifications": [
1074810746
{
1074910747
"query_block": {
@@ -14718,8 +14716,6 @@ EXPLAIN
1471814716
"materialized": {
1471914717
"query_block": {
1472014718
"union_result": {
14721-
"table_name": "<union2,3>",
14722-
"access_type": "ALL",
1472314719
"query_specifications": [
1472414720
{
1472514721
"query_block": {
@@ -14940,8 +14936,6 @@ EXPLAIN
1494014936
"materialized": {
1494114937
"query_block": {
1494214938
"union_result": {
14943-
"table_name": "<union2,3,4>",
14944-
"access_type": "ALL",
1494514939
"query_specifications": [
1494614940
{
1494714941
"query_block": {

mysql-test/main/explain_json.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,6 @@ EXPLAIN
247247
{
248248
"query_block": {
249249
"union_result": {
250-
"table_name": "<union1,2>",
251-
"access_type": "ALL",
252250
"query_specifications": [
253251
{
254252
"query_block": {

mysql-test/main/table_value_constr.result

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,6 @@ EXPLAIN
13041304
{
13051305
"query_block": {
13061306
"union_result": {
1307-
"table_name": "<unit1>",
1308-
"access_type": "ALL",
13091307
"query_specifications": [
13101308
{
13111309
"query_block": {
@@ -1525,8 +1523,6 @@ EXPLAIN
15251523
{
15261524
"query_block": {
15271525
"union_result": {
1528-
"table_name": "<union1,2>",
1529-
"access_type": "ALL",
15301526
"query_specifications": [
15311527
{
15321528
"query_block": {
@@ -1589,8 +1585,6 @@ EXPLAIN
15891585
{
15901586
"query_block": {
15911587
"union_result": {
1592-
"table_name": "<union1,2>",
1593-
"access_type": "ALL",
15941588
"query_specifications": [
15951589
{
15961590
"query_block": {
@@ -1633,8 +1627,6 @@ EXPLAIN
16331627
{
16341628
"query_block": {
16351629
"union_result": {
1636-
"table_name": "<union1,2,3>",
1637-
"access_type": "ALL",
16381630
"query_specifications": [
16391631
{
16401632
"query_block": {
@@ -1677,10 +1669,6 @@ ANALYZE
16771669
{
16781670
"query_block": {
16791671
"union_result": {
1680-
"table_name": "<unit1>",
1681-
"access_type": "ALL",
1682-
"r_loops": 0,
1683-
"r_rows": null,
16841672
"query_specifications": [
16851673
{
16861674
"query_block": {
@@ -1908,10 +1896,6 @@ ANALYZE
19081896
{
19091897
"query_block": {
19101898
"union_result": {
1911-
"table_name": "<union1,2>",
1912-
"access_type": "ALL",
1913-
"r_loops": 0,
1914-
"r_rows": null,
19151899
"query_specifications": [
19161900
{
19171901
"query_block": {
@@ -1976,10 +1960,6 @@ ANALYZE
19761960
{
19771961
"query_block": {
19781962
"union_result": {
1979-
"table_name": "<union1,2>",
1980-
"access_type": "ALL",
1981-
"r_loops": 0,
1982-
"r_rows": null,
19831963
"query_specifications": [
19841964
{
19851965
"query_block": {
@@ -2022,10 +2002,6 @@ ANALYZE
20222002
{
20232003
"query_block": {
20242004
"union_result": {
2025-
"table_name": "<union1,2,3>",
2026-
"access_type": "ALL",
2027-
"r_loops": 0,
2028-
"r_rows": null,
20292005
"query_specifications": [
20302006
{
20312007
"query_block": {

mysql-test/suite/compat/oracle/r/table_value_constr.result

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,6 @@ EXPLAIN
13021302
{
13031303
"query_block": {
13041304
"union_result": {
1305-
"table_name": "<unit1>",
1306-
"access_type": "ALL",
13071305
"query_specifications": [
13081306
{
13091307
"query_block": {
@@ -1523,8 +1521,6 @@ EXPLAIN
15231521
{
15241522
"query_block": {
15251523
"union_result": {
1526-
"table_name": "<union1,2>",
1527-
"access_type": "ALL",
15281524
"query_specifications": [
15291525
{
15301526
"query_block": {
@@ -1587,8 +1583,6 @@ EXPLAIN
15871583
{
15881584
"query_block": {
15891585
"union_result": {
1590-
"table_name": "<union1,2>",
1591-
"access_type": "ALL",
15921586
"query_specifications": [
15931587
{
15941588
"query_block": {
@@ -1631,8 +1625,6 @@ EXPLAIN
16311625
{
16321626
"query_block": {
16331627
"union_result": {
1634-
"table_name": "<union1,2,3>",
1635-
"access_type": "ALL",
16361628
"query_specifications": [
16371629
{
16381630
"query_block": {
@@ -1675,10 +1667,6 @@ ANALYZE
16751667
{
16761668
"query_block": {
16771669
"union_result": {
1678-
"table_name": "<unit1>",
1679-
"access_type": "ALL",
1680-
"r_loops": 0,
1681-
"r_rows": null,
16821670
"query_specifications": [
16831671
{
16841672
"query_block": {
@@ -1906,10 +1894,6 @@ ANALYZE
19061894
{
19071895
"query_block": {
19081896
"union_result": {
1909-
"table_name": "<union1,2>",
1910-
"access_type": "ALL",
1911-
"r_loops": 0,
1912-
"r_rows": null,
19131897
"query_specifications": [
19141898
{
19151899
"query_block": {
@@ -1974,10 +1958,6 @@ ANALYZE
19741958
{
19751959
"query_block": {
19761960
"union_result": {
1977-
"table_name": "<union1,2>",
1978-
"access_type": "ALL",
1979-
"r_loops": 0,
1980-
"r_rows": null,
19811961
"query_specifications": [
19821962
{
19831963
"query_block": {
@@ -2020,10 +2000,6 @@ ANALYZE
20202000
{
20212001
"query_block": {
20222002
"union_result": {
2023-
"table_name": "<union1,2,3>",
2024-
"access_type": "ALL",
2025-
"r_loops": 0,
2026-
"r_rows": null,
20272003
"query_specifications": [
20282004
{
20292005
"query_block": {

sql/sql_explain.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -581,27 +581,29 @@ void Explain_union::print_explain_json(Explain_query *query,
581581
else
582582
writer->add_member("union_result").start_object();
583583

584-
// using_temporary_table
585-
make_union_table_name(table_name_buffer);
586-
writer->add_member("table_name").add_str(table_name_buffer);
587-
writer->add_member("access_type").add_str("ALL"); // not very useful
588-
589-
/* r_loops (not present in tabular output) */
590-
if (is_analyze)
584+
if (using_tmp)
591585
{
592-
writer->add_member("r_loops").add_ll(fake_select_lex_tracker.get_loops());
593-
}
586+
make_union_table_name(table_name_buffer);
587+
writer->add_member("table_name").add_str(table_name_buffer);
588+
writer->add_member("access_type").add_str("ALL"); // not very useful
594589

595-
/* `r_rows` */
596-
if (is_analyze)
597-
{
598-
writer->add_member("r_rows");
599-
if (fake_select_lex_tracker.has_scans())
600-
writer->add_double(fake_select_lex_tracker.get_avg_rows());
601-
else
602-
writer->add_null();
603-
}
590+
/* r_loops (not present in tabular output) */
591+
if (is_analyze)
592+
{
593+
writer->add_member("r_loops").add_ll(
594+
fake_select_lex_tracker.get_loops());
595+
}
604596

597+
/* `r_rows` */
598+
if (is_analyze)
599+
{
600+
writer->add_member("r_rows");
601+
if (fake_select_lex_tracker.has_scans())
602+
writer->add_double(fake_select_lex_tracker.get_avg_rows());
603+
else
604+
writer->add_null();
605+
}
606+
}
605607
writer->add_member("query_specifications").start_array();
606608

607609
for (int i= 0; i < (int) union_members.elements(); i++)

0 commit comments

Comments
 (0)