@@ -48,6 +48,9 @@ typedef struct pgssConstLocations
48
48
int * param_refs ;
49
49
int param_refs_buf_size ;
50
50
int param_refs_count ;
51
+
52
+ /* Should only utility statements be normalized? Set by pg_query_normalize_utility */
53
+ bool normalize_utility_only ;
51
54
} pgssConstLocations ;
52
55
53
56
/*
@@ -398,8 +401,10 @@ static bool const_record_walker(Node *node, pgssConstLocations *jstate)
398
401
case T_RawStmt :
399
402
return const_record_walker ((Node * ) ((RawStmt * ) node )-> stmt , jstate );
400
403
case T_VariableSetStmt :
404
+ if (jstate -> normalize_utility_only ) return false;
401
405
return const_record_walker ((Node * ) ((VariableSetStmt * ) node )-> args , jstate );
402
406
case T_CopyStmt :
407
+ if (jstate -> normalize_utility_only ) return false;
403
408
return const_record_walker ((Node * ) ((CopyStmt * ) node )-> query , jstate );
404
409
case T_ExplainStmt :
405
410
return const_record_walker ((Node * ) ((ExplainStmt * ) node )-> query , jstate );
@@ -408,10 +413,13 @@ static bool const_record_walker(Node *node, pgssConstLocations *jstate)
408
413
case T_AlterRoleStmt :
409
414
return const_record_walker ((Node * ) ((AlterRoleStmt * ) node )-> options , jstate );
410
415
case T_DeclareCursorStmt :
416
+ if (jstate -> normalize_utility_only ) return false;
411
417
return const_record_walker ((Node * ) ((DeclareCursorStmt * ) node )-> query , jstate );
412
418
case T_CreateFunctionStmt :
419
+ if (jstate -> normalize_utility_only ) return false;
413
420
return const_record_walker ((Node * ) ((CreateFunctionStmt * ) node )-> options , jstate );
414
421
case T_DoStmt :
422
+ if (jstate -> normalize_utility_only ) return false;
415
423
return const_record_walker ((Node * ) ((DoStmt * ) node )-> args , jstate );
416
424
case T_CreateSubscriptionStmt :
417
425
record_matching_string (jstate , ((CreateSubscriptionStmt * ) node )-> conninfo );
@@ -428,6 +436,7 @@ static bool const_record_walker(Node *node, pgssConstLocations *jstate)
428
436
return false;
429
437
case T_SelectStmt :
430
438
{
439
+ if (jstate -> normalize_utility_only ) return false;
431
440
SelectStmt * stmt = (SelectStmt * ) node ;
432
441
ListCell * lc ;
433
442
List * fp_and_param_refs_list = NIL ;
@@ -540,6 +549,26 @@ static bool const_record_walker(Node *node, pgssConstLocations *jstate)
540
549
541
550
return false;
542
551
}
552
+ case T_MergeStmt :
553
+ {
554
+ if (jstate -> normalize_utility_only ) return false;
555
+ return raw_expression_tree_walker (node , const_record_walker , (void * ) jstate );
556
+ }
557
+ case T_InsertStmt :
558
+ {
559
+ if (jstate -> normalize_utility_only ) return false;
560
+ return raw_expression_tree_walker (node , const_record_walker , (void * ) jstate );
561
+ }
562
+ case T_UpdateStmt :
563
+ {
564
+ if (jstate -> normalize_utility_only ) return false;
565
+ return raw_expression_tree_walker (node , const_record_walker , (void * ) jstate );
566
+ }
567
+ case T_DeleteStmt :
568
+ {
569
+ if (jstate -> normalize_utility_only ) return false;
570
+ return raw_expression_tree_walker (node , const_record_walker , (void * ) jstate );
571
+ }
543
572
default :
544
573
{
545
574
PG_TRY ();
@@ -558,7 +587,7 @@ static bool const_record_walker(Node *node, pgssConstLocations *jstate)
558
587
return false;
559
588
}
560
589
561
- PgQueryNormalizeResult pg_query_normalize (const char * input )
590
+ PgQueryNormalizeResult pg_query_normalize_ext (const char * input , bool normalize_utility_only )
562
591
{
563
592
MemoryContext ctx = NULL ;
564
593
PgQueryNormalizeResult result = {0 };
@@ -588,6 +617,7 @@ PgQueryNormalizeResult pg_query_normalize(const char* input)
588
617
jstate .param_refs = NULL ;
589
618
jstate .param_refs_buf_size = 0 ;
590
619
jstate .param_refs_count = 0 ;
620
+ jstate .normalize_utility_only = normalize_utility_only ;
591
621
592
622
/* Walk tree and record const locations */
593
623
const_record_walker ((Node * ) tree , & jstate );
@@ -621,6 +651,17 @@ PgQueryNormalizeResult pg_query_normalize(const char* input)
621
651
return result ;
622
652
}
623
653
654
+ PgQueryNormalizeResult pg_query_normalize (const char * input )
655
+ {
656
+ return pg_query_normalize_ext (input , false);
657
+ }
658
+
659
+
660
+ PgQueryNormalizeResult pg_query_normalize_utility (const char * input )
661
+ {
662
+ return pg_query_normalize_ext (input , true);
663
+ }
664
+
624
665
void pg_query_free_normalize_result (PgQueryNormalizeResult result )
625
666
{
626
667
if (result .error ) {
0 commit comments