[MDEV-18306] Optimizer_trace has invalid JSON near rows_estimation Created: 2019-01-18  Updated: 2019-02-13  Resolved: 2019-02-13

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: N/A
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Varun Gupta (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
PartOf
is part of MDEV-6111 optimizer trace Closed

 Description   

I thought that improvements to JSON writer would make this impossible, but
somehow they didn't?

create table ten(a int);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
set optimizer_trace=1;
select * from ten where a<3 ;

produces:

        "steps": [
          {
             ...
          },
          ...
          {
            "ref_optimizer_key_uses": []
          },
          "rows_estimation": [
            {
              "selectivity_for_indexes": [],
              "selectivity_for_columns": []
            },
            {
              "table": "ten",
              "table_scan": {
                "rows": 10,
                "cost": 1
              }
            }
          ],

Note that "rows_estimation" is a named element, but it is in the "steps" array.



 Comments   
Comment by Sergei Petrunia [ 2019-01-18 ]

execution_plan_for_potential_materialization has the same problem.

Comment by Varun Gupta (Inactive) [ 2019-01-21 ]

I added a small patch to see the above irregularity

--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -61,6 +61,7 @@
 #include <my_bit.h>
 #include <hash.h>
 #include <ft_global.h>
+#include "my_json_writer.h"
 
 /*
   A key part number that means we're using a fulltext scan.
@@ -1214,6 +1215,14 @@ JOIN::optimize_inner()
   set_allowed_join_cache_types();
   need_distinct= TRUE;
+  {
+    Json_writer wri;
+    wri.start_array();
+    wri.add_member("varun").start_object();
+    wri.end_object();
+    wri.end_array();
+  }
+

And there is no assert failure , we are trying to add a key-value pair to the array which is incorrect accoring to JSON standards

Comment by Varun Gupta (Inactive) [ 2019-02-13 ]

Fixed as a part of MDEV-6111

Generated at Thu Feb 08 08:43:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.