aboutsummaryrefslogtreecommitdiff
path: root/contrib/pg_stat_statements
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2024-10-22 11:26:05 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2024-10-22 11:26:05 -0400
commit14e5680eee19df8b41ef77330d0b3857f498e4f7 (patch)
tree32b9f1d892be4a0e08523b1ce2d33fbfa9370967 /contrib/pg_stat_statements
parent7c4d3fe272f3ab62b36f21e3fa6ae00751f00e31 (diff)
downloadpostgresql-14e5680eee19df8b41ef77330d0b3857f498e4f7.tar.gz
postgresql-14e5680eee19df8b41ef77330d0b3857f498e4f7.zip
Improve parser's reporting of statement start locations.
Up to now, the parser's reporting of a statement's stmt_location included any preceding whitespace or comments. This isn't really desirable but was done to avoid accounting honestly for nonterminals that reduce to empty. It causes problems for pg_stat_statements, which partially compensates by manually stripping whitespace, but is not bright enough to strip /*-style comments. There will be more problems with an upcoming patch to improve reporting of errors in extension scripts, so it's time to do something about this. The thing we have to do to make it work right is to adjust YYLLOC_DEFAULT to scan the inputs of each production to find the first one that has a valid location (i.e., did not reduce to empty). In theory this adds a little bit of per-reduction overhead, but in practice it's negligible. I checked by measuring the time to run raw_parser() on the contents of information_schema.sql, and there was basically no change. Having done that, we can rely on any nonterminal that didn't reduce to completely empty to have a correct starting location, and we don't need the kluges the stmtmulti production formerly used. This should have a side benefit of allowing parse error reports to include an error position in some cases where they formerly failed to do so, due to trying to report the position of an empty nonterminal. I did not go looking for an example though. The one previously known case where that could happen (OptSchemaEltList) no longer needs the kluge it had; but I rather doubt that that was the only case. Discussion: https://postgr.es/m/ZvV1ClhnbJLCz7Sm@msg.df7cb.de
Diffstat (limited to 'contrib/pg_stat_statements')
-rw-r--r--contrib/pg_stat_statements/expected/select.out5
-rw-r--r--contrib/pg_stat_statements/sql/select.sql3
2 files changed, 5 insertions, 3 deletions
diff --git a/contrib/pg_stat_statements/expected/select.out b/contrib/pg_stat_statements/expected/select.out
index dd6c756f67d..e0e2fa265c9 100644
--- a/contrib/pg_stat_statements/expected/select.out
+++ b/contrib/pg_stat_statements/expected/select.out
@@ -19,8 +19,9 @@ SELECT 1 AS "int";
1
(1 row)
+/* this comment should not appear in the output */
SELECT 'hello'
- -- multiline
+ -- but this one will appear
AS "text";
text
-------
@@ -129,7 +130,7 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
-------+------+------------------------------------------------------------------------------
1 | 1 | PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3
4 | 4 | SELECT $1 +
- | | -- multiline +
+ | | -- but this one will appear +
| | AS "text"
2 | 2 | SELECT $1 + $2
3 | 3 | SELECT $1 + $2 + $3 AS "add"
diff --git a/contrib/pg_stat_statements/sql/select.sql b/contrib/pg_stat_statements/sql/select.sql
index eb45cb81ad2..e0be58d5e24 100644
--- a/contrib/pg_stat_statements/sql/select.sql
+++ b/contrib/pg_stat_statements/sql/select.sql
@@ -12,8 +12,9 @@ SELECT pg_stat_statements_reset() IS NOT NULL AS t;
--
SELECT 1 AS "int";
+/* this comment should not appear in the output */
SELECT 'hello'
- -- multiline
+ -- but this one will appear
AS "text";
SELECT 'world' AS "text";