[MDEV-10339] Invalid JSON Output FROM ANALYZE FORMAT=JSON Created: 2016-07-06  Updated: 2021-12-07  Resolved: 2021-12-06

Status: Closed
Project: MariaDB Server
Component/s: Admin statements, Optimizer
Affects Version/s: 10.1, 10.2
Fix Version/s: 10.8.0

Type: Bug Priority: Minor
Reporter: Brad Jorgensen Assignee: Sergei Petrunia
Resolution: Duplicate Votes: 1
Labels: None

Epic Link: Tracer JSON consistency

 Description   

The output of ANALYZE FORMAT=JSON can be invalid JSON by having multiple table keys in a single object. In the example below, the temporary_table object and the query_block object under subqueries both have multiple table keys. I'm not sure what's being used to create the output JSON, but it might be best to put the tables in a query block group in a tables array instead of in the main object for the query block.

{
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 1484.3,
    "const_condition": "1",
    "filesort": {
      "r_loops": 1,
      "r_total_time_ms": 0.7623,
      "r_used_priority_queue": false,
      "r_output_rows": 409,
      "r_buffer_size": "218Kb",
      "temporary_table": {
        "table": {
          "table_name": "dpgc",
          "access_type": "index",
          "key": "PRIMARY",
          "key_length": "4",
          "used_key_parts": ["id"],
          "r_loops": 1,
          "rows": 406,
          "r_rows": 409,
          "r_total_time_ms": 0.6227,
          "filtered": 100,
          "r_filtered": 100
        },
        "table": {
          "table_name": "dpgct1",
          "access_type": "ref",
          "possible_keys": ["creditor_id"],
          "key": "creditor_id",
          "key_length": "5",
          "used_key_parts": ["creditor_id"],
          "ref": ["db.dpgc.id"],
          "r_loops": 409,
          "rows": 274,
          "r_rows": 497.52,
          "r_total_time_ms": 64.339,
          "filtered": 100,
          "r_filtered": 100,
          "using_index": true
        },
        "table": {
          "table_name": "t2",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "process_date"],
          "key": "PRIMARY",
          "key_length": "4",
          "used_key_parts": ["id"],
          "ref": ["db.dpgct1.trans_id"],
          "r_loops": 203538,
          "rows": 1,
          "r_rows": 0.9983,
          "r_total_time_ms": 602.47,
          "filtered": 50,
          "r_filtered": 29.737,
          "attached_condition": "trigcond(((t2.process_date >= 2016-07-06) and trigcond((dpgct1.trans_id is not null))))"
        },
        "subqueries": [
          {
            "query_block": {
              "select_id": 2,
              "r_loops": 1,
              "r_total_time_ms": 675.79,
              "table": {
                "table_name": "dpgct2",
                "access_type": "index",
                "possible_keys": ["PRIMARY"],
                "key": "creditor_id",
                "key_length": "5",
                "used_key_parts": ["creditor_id"],
                "r_loops": 1,
                "rows": 179946,
                "r_rows": 203488,
                "r_total_time_ms": 44.784,
                "filtered": 100,
                "r_filtered": 100,
                "using_index": true
              },
              "table": {
                "table_name": "t",
                "access_type": "eq_ref",
                "possible_keys": ["PRIMARY", "process_date"],
                "key": "PRIMARY",
                "key_length": "4",
                "used_key_parts": ["id"],
                "ref": ["db.dpgct2.trans_id"],
                "r_loops": 203488,
                "rows": 1,
                "r_rows": 0.9985,
                "r_total_time_ms": 565.77,
                "filtered": 50,
                "r_filtered": 29.736,
                "attached_condition": "(t.process_date >= 2016-07-06)"
              }
            }
          }
        ]
      }
    }
  }
}



 Comments   
Comment by Elena Stepanova [ 2016-07-06 ]

create table t1 (pk1 int primary key, i int);
create table t2 (pk2 int primary key, j int);
insert into t1 values (1,1),(2,2);
insert into t2 values (1,1),(2,2);
analyze format=json select i from t1 where pk1 in (select pk2 from t2);
ANALYZE	{
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 0.2427,
    "table": {
      "table_name": "t1",
      "access_type": "ALL",
      "possible_keys": ["PRIMARY"],
      "r_loops": 1,
      "rows": 2,
      "r_rows": 2,
      "r_total_time_ms": 0.0299,
      "filtered": 100,
      "r_filtered": 100
    },
    "table": {
      "table_name": "t2",
      "access_type": "eq_ref",
      "possible_keys": ["PRIMARY"],
      "key": "PRIMARY",
      "key_length": "4",
      "used_key_parts": ["pk2"],
      "ref": ["test.t1.pk1"],
      "r_loops": 2,
      "rows": 1,
      "r_rows": 1,
      "r_total_time_ms": 0.0565,
      "filtered": 100,
      "r_filtered": 100,
      "using_index": true
    }
  }
}

Comment by Sergei Petrunia [ 2021-12-06 ]

Actually, producing duplicate keys doesn't make the JSON document invalid. We agree that it makes it very hard to process, though.

Comment by Sergei Petrunia [ 2021-12-06 ]

The problem described in this MDEV is fixed in MDEV-27036

Comment by Sergei Petrunia [ 2021-12-06 ]

Closing as Duplicate of MDEV-23076. The fix will be available in MariaDB 10.8

Generated at Thu Feb 08 07:41:27 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.