Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd20d8fb

Browse files
committed
Do not output actual value of location fields in node serialization by default
This changes nodeToString() to not output the actual value of locationfields in nodes, but instead it writes -1. This mirrors the fact thatstringToNode() also does not read location field values but alwaysstores -1.For most uses of nodeToString(), which is to store nodes in catalogfields, this is more useful. We don't store original query texts incatalogs, so any lingering query location values are not meaningful.For debugging purposes, there is a new nodeToStringWithLocations(),which mirrors the existing stringToNodeWithLocations(). This is usedfor WRITE_READ_PARSE_PLAN_TREES and nodes/print.c functions, whichcovers all the debugging uses.Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/CAEze2WgrCiR3JZmWyB0YTc8HV7ewRdx13j0CqD6mVkYAW+SFGQ@mail.gmail.com
1 parent6ae701b commitd20d8fb

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

‎src/backend/nodes/outfuncs.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include"nodes/pg_list.h"
2626
#include"utils/datum.h"
2727

28+
/* State flag that determines how nodeToStringInternal() should treat location fields */
29+
staticboolwrite_location_fields= false;
30+
2831
staticvoidoutChar(StringInfostr,charc);
2932
staticvoidoutDouble(StringInfostr,doubled);
3033

@@ -88,7 +91,7 @@ static void outDouble(StringInfo str, double d);
8891

8992
/* Write a parse location field (actually same as INT case) */
9093
#defineWRITE_LOCATION_FIELD(fldname) \
91-
appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
94+
appendStringInfo(str, " :" CppAsString(fldname) " %d",write_location_fields ?node->fldname : -1)
9295

9396
/* Write a Node field */
9497
#defineWRITE_NODE_FIELD(fldname) \
@@ -757,18 +760,46 @@ outNode(StringInfo str, const void *obj)
757760
/*
758761
* nodeToString -
759762
* returns the ascii representation of the Node as a palloc'd string
763+
*
764+
* write_loc_fields determines whether location fields are output with their
765+
* actual value rather than -1. The actual value can be useful for debugging,
766+
* but for most uses, the actual value is not useful, since the original query
767+
* string is no longer available.
760768
*/
761-
char*
762-
nodeToString(constvoid*obj)
769+
staticchar*
770+
nodeToStringInternal(constvoid*obj,boolwrite_loc_fields)
763771
{
764772
StringInfoDatastr;
773+
boolsave_write_location_fields;
774+
775+
save_write_location_fields=write_location_fields;
776+
write_location_fields=write_loc_fields;
765777

766778
/* see stringinfo.h for an explanation of this maneuver */
767779
initStringInfo(&str);
768780
outNode(&str,obj);
781+
782+
write_location_fields=save_write_location_fields;
783+
769784
returnstr.data;
770785
}
771786

787+
/*
788+
* Externally visible entry points
789+
*/
790+
char*
791+
nodeToString(constvoid*obj)
792+
{
793+
returnnodeToStringInternal(obj, false);
794+
}
795+
796+
char*
797+
nodeToStringWithLocations(constvoid*obj)
798+
{
799+
returnnodeToStringInternal(obj, true);
800+
}
801+
802+
772803
/*
773804
* bmsToString -
774805
* returns the ascii representation of the Bitmapset as a palloc'd string

‎src/backend/nodes/print.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ print(const void *obj)
3838
char*s;
3939
char*f;
4040

41-
s=nodeToString(obj);
41+
s=nodeToStringWithLocations(obj);
4242
f=format_node_dump(s);
4343
pfree(s);
4444
printf("%s\n",f);
@@ -56,7 +56,7 @@ pprint(const void *obj)
5656
char*s;
5757
char*f;
5858

59-
s=nodeToString(obj);
59+
s=nodeToStringWithLocations(obj);
6060
f=pretty_format_node_dump(s);
6161
pfree(s);
6262
printf("%s\n",f);
@@ -74,7 +74,7 @@ elog_node_display(int lev, const char *title, const void *obj, bool pretty)
7474
char*s;
7575
char*f;
7676

77-
s=nodeToString(obj);
77+
s=nodeToStringWithLocations(obj);
7878
if (pretty)
7979
f=pretty_format_node_dump(s);
8080
else

‎src/backend/tcop/postgres.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ pg_parse_query(const char *query_string)
641641
*/
642642
#ifdefWRITE_READ_PARSE_PLAN_TREES
643643
{
644-
char*str=nodeToString(raw_parsetree_list);
644+
char*str=nodeToStringWithLocations(raw_parsetree_list);
645645
List*new_list=stringToNodeWithLocations(str);
646646

647647
pfree(str);
@@ -849,7 +849,7 @@ pg_rewrite_query(Query *query)
849849
foreach(lc,querytree_list)
850850
{
851851
Query*curr_query=lfirst_node(Query,lc);
852-
char*str=nodeToString(curr_query);
852+
char*str=nodeToStringWithLocations(curr_query);
853853
Query*new_query=stringToNodeWithLocations(str);
854854

855855
/*
@@ -931,7 +931,7 @@ pg_plan_query(Query *querytree, const char *query_string, int cursorOptions,
931931
char*str;
932932
PlannedStmt*new_plan;
933933

934-
str=nodeToString(plan);
934+
str=nodeToStringWithLocations(plan);
935935
new_plan=stringToNodeWithLocations(str);
936936
pfree(str);
937937

‎src/include/nodes/nodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ extern void outBitmapset(struct StringInfoData *str,
195195
externvoidoutDatum(structStringInfoData*str,uintptr_tvalue,
196196
inttyplen,booltypbyval);
197197
externchar*nodeToString(constvoid*obj);
198+
externchar*nodeToStringWithLocations(constvoid*obj);
198199
externchar*bmsToString(conststructBitmapset*bms);
199200

200201
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp