aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-07-27 09:42:33 +0900
committerMichael Paquier <michael@paquier.xyz>2023-07-27 09:42:33 +0900
commit31de7e60da34761365f94dc76cc2c1bf2172d1bc (patch)
tree4220dce9f328eecccdcf04d0120b9d44d5b0983e /src/backend/parser
parent19c590f6a795831b34782a4d69fa6a52dc9d03c3 (diff)
downloadpostgresql-31de7e60da34761365f94dc76cc2c1bf2172d1bc.tar.gz
postgresql-31de7e60da34761365f94dc76cc2c1bf2172d1bc.zip
Show savepoint names as constants in pg_stat_statements
In pg_stat_statements, savepoint names now show up as constants with a parameter symbol, using as base query string the one added as a new entry to the PGSS hash table, leading to: RELEASE $1 ROLLBACK TO $1 SAVEPOINT $1 Applying constants to these query parts is a huge advantage for workloads that generate randomly savepoint points, like ORMs (Django is at the origin of this patch). The ODBC driver is a second layer that likes a lot savepoints, though it does not use a random naming pattern. A "location" field is added to TransactionStmt, now set only for savepoints. The savepoint name is ignored by the query jumbling. The location can be extended to other query patterns, if required, like 2PC commands. Some tests are added to pg_stat_statements for all the query patterns supported by the parser. ROLLBACK, ROLLBACK TO SAVEPOINT and ROLLBACK TRANSACTION TO SAVEPOINT have the same Node representation, so all these are equivalents. The same happens for RELEASE and RELEASE SAVEPOINT. Author: Greg Sabino Mullane Discussion: https://postgr.es/m/CAKAnmm+2s9PA4OaumwMJReWHk8qvJ_-g1WqxDRDAN1BSUfxyTw@mail.gmail.com
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 856d5dee0e7..15ece871a01 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -10841,6 +10841,7 @@ TransactionStmt:
n->kind = TRANS_STMT_ROLLBACK;
n->options = NIL;
n->chain = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| START TRANSACTION transaction_mode_list_or_empty
@@ -10849,6 +10850,7 @@ TransactionStmt:
n->kind = TRANS_STMT_START;
n->options = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| COMMIT opt_transaction opt_transaction_chain
@@ -10858,6 +10860,7 @@ TransactionStmt:
n->kind = TRANS_STMT_COMMIT;
n->options = NIL;
n->chain = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| ROLLBACK opt_transaction opt_transaction_chain
@@ -10867,6 +10870,7 @@ TransactionStmt:
n->kind = TRANS_STMT_ROLLBACK;
n->options = NIL;
n->chain = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| SAVEPOINT ColId
@@ -10875,6 +10879,7 @@ TransactionStmt:
n->kind = TRANS_STMT_SAVEPOINT;
n->savepoint_name = $2;
+ n->location = @2;
$$ = (Node *) n;
}
| RELEASE SAVEPOINT ColId
@@ -10883,6 +10888,7 @@ TransactionStmt:
n->kind = TRANS_STMT_RELEASE;
n->savepoint_name = $3;
+ n->location = @3;
$$ = (Node *) n;
}
| RELEASE ColId
@@ -10891,6 +10897,7 @@ TransactionStmt:
n->kind = TRANS_STMT_RELEASE;
n->savepoint_name = $2;
+ n->location = @2;
$$ = (Node *) n;
}
| ROLLBACK opt_transaction TO SAVEPOINT ColId
@@ -10899,6 +10906,7 @@ TransactionStmt:
n->kind = TRANS_STMT_ROLLBACK_TO;
n->savepoint_name = $5;
+ n->location = @5;
$$ = (Node *) n;
}
| ROLLBACK opt_transaction TO ColId
@@ -10907,6 +10915,7 @@ TransactionStmt:
n->kind = TRANS_STMT_ROLLBACK_TO;
n->savepoint_name = $4;
+ n->location = @4;
$$ = (Node *) n;
}
| PREPARE TRANSACTION Sconst
@@ -10915,6 +10924,7 @@ TransactionStmt:
n->kind = TRANS_STMT_PREPARE;
n->gid = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| COMMIT PREPARED Sconst
@@ -10923,6 +10933,7 @@ TransactionStmt:
n->kind = TRANS_STMT_COMMIT_PREPARED;
n->gid = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| ROLLBACK PREPARED Sconst
@@ -10931,6 +10942,7 @@ TransactionStmt:
n->kind = TRANS_STMT_ROLLBACK_PREPARED;
n->gid = $3;
+ n->location = -1;
$$ = (Node *) n;
}
;
@@ -10942,6 +10954,7 @@ TransactionStmtLegacy:
n->kind = TRANS_STMT_BEGIN;
n->options = $3;
+ n->location = -1;
$$ = (Node *) n;
}
| END_P opt_transaction opt_transaction_chain
@@ -10951,6 +10964,7 @@ TransactionStmtLegacy:
n->kind = TRANS_STMT_COMMIT;
n->options = NIL;
n->chain = $3;
+ n->location = -1;
$$ = (Node *) n;
}
;