SND on Postgres: fix recursive CTEs and LabKey-SQL queries#929
Open
labkey-martyp wants to merge 3 commits intorelease26.3-SNAPSHOTfrom
Open
SND on Postgres: fix recursive CTEs and LabKey-SQL queries#929labkey-martyp wants to merge 3 commits intorelease26.3-SNAPSHOTfrom
labkey-martyp wants to merge 3 commits intorelease26.3-SNAPSHOTfrom
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.
Rationale
Follow-up fixes to the SND PostgreSQL migration in 26.3. The recursive CTEs in
snd.fGetSuperPkgandsnd.fGetProjectItemsproduced collidingTreePathsegments under PostgreSQL because window functions are forbidden in the recursive term ofWITH RECURSIVE, so SortOrder was being formatted directly into a 3-character right-justified string. Two LabKey-SQL queries (DeletedLookupSets,DeletedLookups) still used MSSQL-specific functions (charindex,len) that don't resolve in LabKey SQL after the move to PG.SNDManager.updateProjectFieldhad a generic field-name-as-string parameter that was concatenated into a SQL string but only ever called with"EndDate"— tightening it removes a latent SQL-injection shape.Changes
snd/resources/schemas/dbscripts/postgresql/snd-0.000-25.000.sql) — Rewrotesnd.fGetSuperPkgandsnd.fGetProjectItemsto pre-compute per-parent ordinals in a non-recursive CTE (ROW_NUMBER() OVER (PARTITION BY ParentSuperPkgId ORDER BY SortOrder NULLS FIRST, SuperPkgId)), then join to it from both the anchor and recursive members.TreePathsegments now useLPAD(Ordinal::TEXT, 6, '0')instead ofRIGHT(REPEAT(' ', 3) || COALESCE(SortOrder, 0)::VARCHAR, 3), eliminating the 3-character truncation and the collisions between siblings that share aSortOrder.NULLS FIRSTmatches the MSSQL twin's default NULL ordering and the prior PGCOALESCE(SortOrder, 0)behavior. Inline comments call out the divergence from thesqlserver/twin and recommend aligning MSSQL later.snd/resources/queries/snd/DeletedLookupSets.sql,DeletedLookups.sql) — Replaced MSSQL-onlycharindex(...)/len(...)with the LabKey-SQL portablelocate(...)/length(...)so these queries resolve under PostgreSQL.SNDManager.updateProjectField→updateProjectEndDate— The only call site ever passed"EndDate"for the field parameter. The method now hardcodesSET EndDate = ?, dropping the field-name string concatenation. No behavior change at the call site; removes a SQL-injection-shaped parameter and a stale doc comment.Notes for reviewers
snd-0.000-25.000.sqlscript can be edited in place — there are no deployed installs that would need an incremental upgrade script.