Obfuscate EXTRACT field keywords#98
Merged
Merged
Conversation
The pg_stat_statements form `EXTRACT($1 FROM x)` and the pg_stat_activity form `EXTRACT(epoch FROM x)` previously produced different obfuscated signatures: the positional parameter was replaced with `?` while the unquoted field keyword was preserved as an identifier. This split one logical query into two DBM signatures. Track EXTRACT( context in the obfuscator and replace the field argument with `?` when it matches a known PostgreSQL field name (epoch, year, month, dow, etc.). Bare `epoch` outside an EXTRACT call and unrecognized field names are left untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lu-zhengda
approved these changes
May 5, 2026
This was referenced May 5, 2026
joelmarcotte
added a commit
that referenced
this pull request
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Summary
EXTRACT(epoch FROM ...)was obfuscated differently depending on capture path: pg_stat_statements normalizes toEXTRACT($1 FROM ...)(replaced with?), while pg_stat_activity preservedepochas an unquoted identifier.EXTRACT(context and rewrites the field argument to?when it matches a known PostgreSQL field name (epoch,year,month,dow,isodow,microseconds,timezone_hour, etc.), so both code paths converge onEXTRACT(? FROM x).epochoutside an EXTRACT call (e.g. a column reference) and unrecognized field names are left alone, so user identifiers aren't accidentally rewritten.Test plan
go test ./...passes (existing + new)obfuscator_test.gocover the standaloneObfuscatepath: positive cases (lowercase, uppercase, mixed-case fields), positional parameter regression, and negative cases (epochas a column, unknown field name)testdata/postgresql/select/coverObfuscateAndNormalize:extract-epoch-field.json— primary regression test for the customer issueextract-various-fields.json—year/month/dow/microseconds/timezone_hourin one queryextract-positional-parameter.json— pg_stat_statements formextract-quoted-string-field.json—EXTRACT('epoch' FROM x)(string literal alternative)date-trunc-string-literal.json,date-part-string-literal.json— already obfuscated, locked inextract-field-name-as-column.json— confirmsepoch/yearoutside EXTRACT remain untouchedBenchmarkObfuscator*shows no measurable regression (the change adds two string compares per non-whitespace token)🤖 Generated with Claude Code