Repository navigation
Add opt-in PostgreSQL IS predicate literal preservation - #114
Open
joelmarcotte wants to merge 3 commits into
Open
joelmarcotte wants to merge 3 commits into
joelmarcotte wants to merge 3 commits into
Conversation
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
WithKeepISPredicate(bool)andkeep_is_predicate, disabled by default.TRUE,FALSE, andNULLon the right ofISandIS NOTin bothObfuscateandObfuscateAndNormalize.IS [NOT] DISTINCT FROMforms, ordinary literals, and positional binds on the existing replacement rules. Add the CLI flag and README guidance.The existing
keep_booleanandkeep_nullsemantics remain intact. Enabling this option in DBM changes query signatures and requires a coordinated sample, metrics, controller, and proxy rollout. This PR changes only go-sqllexer; it does not change Agent, integrations-core, dd-source, or PgProxy.Validation
go test ./...passed.gofmt;git diff --checkpassed.ReplaceBoolean/ReplaceNullcombinations with the option off and on through both public processing paths. The off goldens were captured fromorigin/mainbefore the change.obfuscateandobfuscate_and_normalize.Performance
Added
BenchmarkKeepISPredicatefor queries with no predicate, one predicate, and mixed predicates through both processing paths. On an Apple M5 Pro with Go 1.27.1 (-benchmem -benchtime=300ms -count=5), option-off medians were within about 2% ofmain. Option-on added roughly 3–7% CPU time inObfuscateand 2–3% inObfuscateAndNormalize. Both settings had the same allocation count: 5 perObfuscatecall and 6 perObfuscateAndNormalizecall in these cases. The mixed normalized output used 16 more bytes with the option on because it retains literal text. CPU and allocation profiles showed no allocation in the new predicate check; the measured allocations remain in the lexer, output builder, and normalizer.PostgreSQL comparison
An isolated local PostgreSQL 18.6 (Homebrew) instance used
shared_preload_libraries=pg_stat_statements,compute_query_id=auto,standard_conforming_strings=on,pg_stat_statements.track=top,track_utility=on,track_planning=off,max=5000, andsave=on.pg_stat_statementsreportedSELECT $1 IS DISTINCT FROM $2for rawSELECT TRUE IS DISTINCT FROM FALSE, andSELECT $1 IS NOT DISTINCT FROM $2for rawSELECT TRUE IS NOT DISTINCT FROM FALSE. Preserving the right-handFALSEwould split raw-sample and representative-text signatures. This PR therefore defers bothDISTINCT FROMforms. With the option enabled and boolean and positional parameter replacement on, both sources normalize toSELECT ? IS DISTINCT FROM ?(orSELECT ? IS NOT DISTINCT FROM ?).SELECT TRUE IS TRUEalso matched its representative text while keeping the right-handTRUE.