OSDN Git Service

Version 1.3.1
[pgstoreplans/pg_store_plans.git] / json2sql.pl
index d812d06..a83d824 100755 (executable)
@@ -15,19 +15,26 @@ INSERT INTO plans (VALUES
 EOS
 
 $plan_no = -1;
-$title = "###### Plan $plan_no: all properties";
+$title = "###### Plan $plan_no: all properties 1/2";
 setplan0(0);  # Without "Unknown Key"
 print "($plan_no, \'$title\',\n";
 print " $escape'$plan')";
 $plan_no--;
 
-$title = "###### Plan $plan_no: all properties plus unknown key";
+$title = "###### Plan $plan_no: all properties 2/2";
+setplan1();
+print ",($plan_no, \'$title\',\n";
+print " $escape'$plan')";
+$plan_no--;
+
+$title = "###### Plan $plan_no: some properties plus unknown key";
 setplan0(1);  # With "Unknown Key"
 print ",($plan_no, \'$title\',\n";
 print " $escape'$plan')";
 
 $plan_no = 1;
 $state = 0;
+$indent = "";
 while(<>) {
        chomp;
        if ($state == 0) {
@@ -35,15 +42,24 @@ while(<>) {
                $title = "###### Plan $plan_no: $1";
                $state = 1;
        } elsif ($state == 1) {
+               # edit auto_explain's result
+               next if (/^psql:makeplanfile.sql/);
+
                if (/[}\]:,]/) {
                        die("??? : $_");
                }
-               next if (!/^   { *\+$/);
+               next if (!/^( *){ *\+?$/);
+        $indent = $1;
                $plan = $_;
                $plan =~ s/^   (.*[^ ]) *\+$/$1\n/;
+               chomp($plan);
+               $plan .= "\n";
                $state = 2;
        } elsif ($state == 2) {
-               if (/^   } *\+$/) {
+               # edit auto_explain's result
+               next if (/^  "Query Text":/);
+
+               if (/^$indent} *\+?$/) {
                        $state = 3;
                }
                $l = $_;
@@ -80,9 +96,9 @@ print <<'EOS';
 UPDATE plans SET splan = pg_store_plans_shorten(lplan);
 
 \echo ###### tag abbreviation test
-SELECT splan FROM plans WHERE id = -1;
+SELECT splan FROM plans WHERE id in (-1, -2);
 
-\echo ###### JSON properties round-trip test
+\echo ###### JSON properties round-trip test: !!! This shouldn''''t return a row
 SELECT id FROM plans
        where pg_store_plans_jsonplan(splan) <> lplan;
 
@@ -101,7 +117,8 @@ SELECT '### '||'xml-short        '||title||E'\n'||
 \echo  ###### text format output test
 SELECT '### '||'TEXT-short       '||title||E'\n'||
   pg_store_plans_textplan(splan)
-  FROM plans ORDER BY id;
+  FROM plans WHERE id >= 0 ORDER BY id;
+
 
 \echo  ###### long-json-as-a-source test
 SELECT '### '||'yaml-long JSON   '||title||E'\n'||
@@ -182,6 +199,12 @@ sub setplan0 {
   "Node Type": "SetOp",
   "Node Type": "LockRows",
   "Node Type": "Limit",
+  "Node Type": "Sample Scan",
+  "Node Type": "Gather",
+  "Node Type": "ProjectSet",
+  "Node Type": "Table Function Scan",
+  "Node Type": "Named Tuplestore Scan",
+  "Node Type": "Gather Merge",
   "Parent Relationship": "Outer",
   "Parent Relationship": "Inner",
   "Parent Relationship": "Subquery",
@@ -202,6 +225,7 @@ sub setplan0 {
   "Strategy": "Plain",
   "Strategy": "Sorted",
   "Strategy": "Hashed",
+  "Strategy": "Mixed",
   "Join Type": "Inner",
   "Join Type": "Left",
   "Join Type": "Full",
@@ -218,12 +242,27 @@ sub setplan0 {
   "Sort Method": "external merge",
   "Sort Method": "still in progress",
   "Sort Key": "a",
+  "Group Key": "a",
+  "Grouping Sets": "a",
+  "Group Keys": "a",
+  "Hash Keys": "a",
+  "Hash Key": "a",
+  "Parallel Aware": "true",
+  "Workers Planned": "0",
+  "Workers Launched": "0",
+  "Workers": "x",
+  "Worker Number": "0",
   "Filter": "a",
   "Join Filter": "a",
   "Hash Cond": "a",
   "Index Cond": "a",
   "TID Cond": "a",
   "Recheck Cond": "a",
+  "Conflict Resolution": "a",
+  "Conflict Arbiter Indexes": "a",
+  "Tuples Inserted": 0,
+  "Conflicting Tuples": 0,
+  "Target Tables": "a",
   "Operation": "Insert",
   "Operation": "Delete",
   "Operation": "Update",
@@ -260,7 +299,20 @@ sub setplan0 {
   "Sort Space Type": "Memory",
   "Peak Memory Usage": 0,
   "Original Hash Batches": 0,
-  "Original Hash Buckets": 0,
+  "Original Hash Buckets": 0
+EOS
+chop $plan;
+if ($addunknown) {
+       $plan .= ",\n  \"Unknown Key\": \"Unknown Value\"";
+}
+$plan .= "\n}";
+
+}
+
+sub setplan1 {
+       my($addunknown) = @_;
+       $plan = << 'EOS';
+{
   "Hash Batches": 0,
   "Hash Buckets": 0,
   "Rows Removed by Filter": 0,
@@ -271,13 +323,23 @@ sub setplan0 {
   "Execution Time": 0,
   "Exact Heap Blocks": 0,
   "Lossy Heap Blocks": 0,
-  "Rows Removed by Join Filter": 0
+  "Rows Removed by Join Filter": 0,
+  "Target Tables": "dummy",
+  "Conflict Resolution": "NOTHING",
+  "Conflict Arbiter Indexes": "ia",
+  "Tuples Inserted": 123,
+  "Conflicting Tuples": 234,
+  "Sampling Method": "system",
+  "Sampling Parameters": ["''10''::real"],
+  "Repeatable Seed": "''0''::double precision",
+  "Workers": "dummy",
+  "Worker Number": 0
 EOS
-chop $plan;
-if ($addunknown) {
-       $plan .= ",\n  \"Unknown Key\": \"Unknown Value\"";
-}
-$plan .= "\n}";
+
+# Avoid trailing new line
+$plan .= "}";
 
 }
 
+
+