Implement WRITE_READ_PARSE_PLAN_TREES for raw parse trees
authorTom Lane <[email protected]>
Mon, 26 Sep 2022 14:32:16 +0000 (16:32 +0200)
committerPeter Eisentraut <[email protected]>
Mon, 26 Sep 2022 14:32:16 +0000 (16:32 +0200)
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/4159834.1657405226@sss.pgh.pa.us

src/backend/tcop/postgres.c

index 35eff28bd363de0eacef4119b36919a5a10c4654..4952d0118360373a62a9fc429c5de17cc5171c17 100644 (file)
@@ -603,10 +603,22 @@ pg_parse_query(const char *query_string)
 #endif
 
    /*
-    * Currently, outfuncs/readfuncs support is missing for many raw parse
-    * tree nodes, so we don't try to implement WRITE_READ_PARSE_PLAN_TREES
-    * here.
+    * Optional debugging check: pass raw parsetrees through
+    * outfuncs/readfuncs
     */
+#ifdef WRITE_READ_PARSE_PLAN_TREES
+   {
+       char       *str = nodeToString(raw_parsetree_list);
+       List       *new_list = stringToNodeWithLocations(str);
+
+       pfree(str);
+       /* This checks both outfuncs/readfuncs and the equal() routines... */
+       if (!equal(new_list, raw_parsetree_list))
+           elog(WARNING, "outfuncs/readfuncs failed to produce an equal raw parse tree");
+       else
+           raw_parsetree_list = new_list;
+   }
+#endif
 
    TRACE_POSTGRESQL_QUERY_PARSE_DONE(query_string);