Repository navigation
SQLRDD: sort keys like REF_NR+DTOS(DATUM) by their columns - #2122
Merged
RobertvanderHulst merged 1 commit intoOct 27, 2026
Merged
Conversation
An order whose key contains a function was sorted by the SQL translation of the whole key text, e.g. ORDER BY [REF_NR] + CONVERT(char(8),[DATUM],112). The server cannot read that order from the index on (REF_NR, DATUM), so it computed and sorted the text for the whole order on every page and every GoBottom(). A key that only concatenates columns and DTOS(column) is now sorted by the columns themselves: DTOS() keeps the order of the date and the other parts are fixed-width columns, so the order is the same and the server can use the index. SqlDbExpression.KeyTerms describes such a key. Seek and scope conditions on these keys are built per part as well (the column-aware conditions so far only handled keys without any function), the DTOS() part compared as its yyyymmdd text, and now also for a value of the full key length: a relation seek on REF_NR+DTOS(DATUM) becomes [REF_NR] = ... AND CONVERT(char(8),[DATUM],112) = ... instead of a comparison on the concatenated text that no index can serve. A value longer than the key parts still uses the condition on the whole key text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
An order whose key contains a function was sorted by the SQL translation of the whole key text, e.g.
ORDER BY [REF_NR] + CONVERT(char(8),[DATUM],112). The server cannot read that order from the index on(REF_NR, DATUM), so it computed and sorted the text for the whole order on every page and everyGoBottom(). Keys like this are very common in xBase applications: our ERP has 115 tags withDTOS().Change
DTOS(column)is now sorted by the columns themselves.DTOS()keeps the order of the date and the other parts are fixed-width columns, so the order is the same and the server can use the index. The newSqlDbExpression.KeyTermsdescribes such a key.DTOS()part is compared as itsyyyymmddtext.REF_NR+DTOS(DATUM)becomes[REF_NR] = ... AND CONVERT(char(8),[DATUM],112) = ...instead of a comparison on the concatenated text that no index can serve. A value longer than the key parts still uses the condition on the whole key text.Measurements
KDKONTO copy with 103,000 rows, tag
REF_NR+DTOS(BEL_DAT)+BEL_ART+BEL_NR, server time per query:Testing
For all 115
DTOS()tags of our ERP I compared the old and the new build:All results are identical.
🤖 Generated with Claude Code