WIP: command_tag_format — protocol-level command tag negotiation via _pq_#16
Open
NikolayS wants to merge 2720 commits into
Open
WIP: command_tag_format — protocol-level command tag negotiation via _pq_#16NikolayS wants to merge 2720 commits into
NikolayS wants to merge 2720 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(live hacking session: https://www.youtube.com/watch?v=VKuxQZlvd8E)
Adds a new protocol-level feature
_pq_.command_tag_formatthat allows clients to negotiate richer command completion tags at connection time.The problem
Every INSERT returns
INSERT 0 N— the0is a vestigial OID field, hardcoded to zero since PG12 dropped table OIDs. It wastes bytes and confuses users, but changing the wire format breaks old clients.Solution: protocol negotiation
New clients send
_pq_.command_tag_formatin the startup packet. Old clients never send it, so they always get legacy format. Zero breakage.Formats
legacyINSERT 0 N(default)INSERT 0 1verboseINSERT tablename NINSERT users 1fqnINSERT schema.tablename NINSERT public.users 1verboseandfqnalso work for UPDATE, DELETE, and MERGE.Safety guarantees
_pq_)INSERT 0 1— always safe_pq_sent)SET command_tag_format = 'verbose'options=-ccommand_tag_format=verboseThe GUC is
PGC_INTERNAL— only the_pq_startup packet path can set it.SET,options=-c,ALTER SYSTEM, andpostgresql.confare all blocked.Implementation (8 files, ~115 insertions)
cmdtag.h/cmdtag.c— format constants, format-awareBuildQueryCompletionStringpquery.c— populates relation name from executor for verbose/fqnbackend_startup.c—_pq_handler, stores inPort->pq_command_tag_formatlibpq-be.h— newPortfield for deferred protocol optionpostinit.c— deferred application viaSetConfigOption(PGC_INTERNAL, PGC_S_OVERRIDE)guc_parameters.dat/guc_tables.c— GUC registration withGUC_REPORTNOT changed:
fe-exec.c(libpq)Old protocol is completely untouched. New-protocol-aware clients handle the new format themselves.
Evolution
command_tag_omit_oid— simple bool GUC (PGC_USERSET) + libpq patchcommand_tag_format— enum with 4 modes,_pq_negotiation,GUC_REPORTPGC_INTERNAL, removedmodernmode, reverted libpq, separatePortfield +PGC_S_OVERRIDEdeferred applicationTest results
See comment with full test evidence — 8/8 scenarios pass with both stock PG17 psql and raw
_pq_startup packet test.