Skip to content

Fix greedy comment regex and deallocate-all blast radius (stacked on #14) - #15

Closed
utkarash2991 wants to merge 1 commit into
utkarashsingh/psqlext-1773-schema-qualify-hypopg-calls-v2from
utkarashsingh/psqlext-1773-fix-comment-regex-and-deallocate
Closed

utkarash2991 wants to merge 1 commit into
utkarashsingh/psqlext-1773-schema-qualify-hypopg-calls-v2from
utkarashsingh/psqlext-1773-fix-comment-regex-and-deallocate

Conversation

@utkarash2991

@utkarash2991 utkarash2991 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #14

Targets utkarashsingh/psqlext-1773-schema-qualify-hypopg-calls-v2 (#14), not main - merge #13 and #14 first.

Two issues found reviewing the function while working on PSQLEXT-1773, both silent (no error raised) and both verified before and after the fix:

1. Greedy block-comment regex deletes code between separate comments

The comment-stripping regex ('\/\*.+\*\/') is greedy across every /* */ pair in the query, not just the nearest one. A query with two separate block comments has everything between the first /* and the last */ deleted - including real code in between.

select regexp_replace('select /* c1 */ a /* c2 */ from t', '\/\*.+\*\/', '', 'g');
-- 'select  from t'  <- column "a" is gone

Fixed with a non-greedy quantifier (\/\*.+?\*\/).

2. deallocate all wipes every prepared statement in the session

The two bare deallocate all; calls clear every prepared statement in the calling session, not just index_advisor's own internal one. In a pooled or persistent connection (PostgREST, pgbouncer session mode) this silently breaks whatever else that connection had prepared.

Verified: preparing an unrelated statement, then calling index_advisor(), left pg_prepared_statements with 0 rows afterward.

Fixed by checking pg_prepared_statements for the specific name before deallocating it.

Tracked in https://linear.app/supabase/issue/PSQLEXT-1773

@utkarash2991
utkarash2991 added this pull request to stack #16 October 5, 2026 19:47
@utkarash2991
utkarash2991 requested a review from a team October 5, 2026 19:51
@utkarash2991
utkarash2991 force-pushed the utkarashsingh/psqlext-1773-fix-comment-regex-and-deallocate branch from 3c6b3f7 to b835380 Compare October 6, 2026 10:47
Two issues found during review of the function, both silent and both
real:

1. The block-comment regex ('\/\*.+\*\/') is greedy across every /* */
   pair in the query, not just one. A query with two separate block
   comments had everything between the first "/*" and the last "*/"
   deleted - including real code in between - with no error raised.
   Verified: regexp_replace('select /* c1 */ a /* c2 */ from t',
   '\/\*.+\*\/', '', 'g') returns 'select  from t' - the column "a" is
   gone. Fixed with a non-greedy quantifier.

2. The two bare "deallocate all;" calls wipe every prepared statement in
   the calling session, not just index_advisor's own internal one.
   Verified: preparing an unrelated statement, then calling
   index_advisor(), left pg_prepared_statements with 0 rows. In a pooled
   or persistent connection (PostgREST, pgbouncer session mode) this
   silently breaks whatever else that connection had prepared. Fixed by
   checking pg_prepared_statements for the specific name before
   deallocating it - DEALLOCATE has no IF EXISTS clause, so this needs an
   explicit existence check rather than DROP-style IF EXISTS syntax
   (caught by the new test on the first attempt).

Ships as 0.2.2, as an incremental upgrade script on top of 0.2.1.
@utkarash2991
utkarash2991 force-pushed the utkarashsingh/psqlext-1773-fix-comment-regex-and-deallocate branch from b835380 to 19ab033 Compare October 6, 2026 10:51
extversion
------------
0.2.1
0.2.2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it does not make sense to bump extension version on all PRs. How about keeping 0.2.1 as it is not released yet?

An error occurred while trying to automatically change base from utkarashsingh/psqlext-1773-schema-qualify-hypopg-calls-v2 to main October 8, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants