OSDN Git Service

Give correct query location to generate_normalized_query.
authorKyotaro Horiguchi <horikyota.ntt@gmail.com>
Mon, 17 Feb 2020 04:15:39 +0000 (13:15 +0900)
committerKyotaro Horiguchi <horikyota.ntt@gmail.com>
Mon, 17 Feb 2020 04:43:13 +0000 (13:43 +0900)
There was a thinko about query_loc of generate_normalized_query which
causes a crash. For example a query is following a sequence of
semicolons (by \; in psql input) longer than the length after the last
placeholder to the end of the query, the function causes assertion
failure. Anyway prepared statements lose that value so we just pass 0
as the query_loc for consistent behavior.

expected/ut-T.out
pg_hint_plan.c
sql/ut-T.sql

index d5fe9e0..8b5f565 100644 (file)
@@ -127,5 +127,12 @@ error hint:
 (2 rows)
 
 DEALLOCATE p1;
+-- Check proper calling to generate_normalized_query
+\;\;SELECT 1,2;
+ ?column? | ?column? 
+----------+----------
+        1 |        2
+(1 row)
+
 SET pg_hint_plan.enable_hint_table to off;
 DELETE FROM hint_plan.hints;
index 71124a7..2a4930f 100644 (file)
@@ -2868,9 +2868,7 @@ get_current_hint_string(ParseState *pstate, Query *query)
                         */
                        query_len = strlen(query_str) + 1;
                        normalized_query =
-                               generate_normalized_query(&jstate, query_str,
-                                                                                 query->stmt_location,
-                                                                                 &query_len,
+                               generate_normalized_query(&jstate, query_str, 0, &query_len,
                                                                                  GetDatabaseEncoding());
 
                        /*
index 98caf68..48a0be3 100644 (file)
@@ -41,5 +41,9 @@ EXPLAIN CREATE TABLE ct1 AS EXECUTE p1;
 
 DEALLOCATE p1;
 
+-- Check proper calling to generate_normalized_query
+\;\;SELECT 1,2;
+
 SET pg_hint_plan.enable_hint_table to off;
 DELETE FROM hint_plan.hints;
+