Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with longish concatenated context aliases #8494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dyemanov
Copy link
Member

@dyemanov dyemanov commented Apr 1, 2025

Currently nested contexts (e.g. derived tables) have context aliases concatenated through the whole stack, so the final string is not limited to the maximum metadata name length.

  1. Fix the comparison order to avoid an alias being truncated while compared
  2. Make planEntry.alias a string rather than MetaName
  3. Truncate the concatenated alias when generating BLR

All these issues now assert: (1) and (2) for aliases longer than 252 bytes and (3) for aliases longer than 255 bytes.

@dyemanov dyemanov requested a review from asfernandes April 1, 2025 17:05
@dyemanov dyemanov self-assigned this Apr 1, 2025
@dyemanov
Copy link
Member Author

dyemanov commented Apr 1, 2025

Test case is available upon request.

Copy link
Member

@asfernandes asfernandes left a comment

Choose a reason for hiding this comment

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

The adaptation of plans to the schemas PR was really trick.
Maybe you can do the master changes based on it or in the same branch?

{
string truncatedAlias(alias);
truncatedAlias.resize(MAX_UCHAR - 3);
truncatedAlias += "...";
Copy link
Member

Choose a reason for hiding this comment

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

How this change of a name overflow to ellipsis will resolve problems?

Copy link
Member Author

Choose a reason for hiding this comment

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

It avoids an assertion (debug build) or weird alias truncation (release build) inside BlrWriter::appendString when called from genBlr(). Of course, we could just truncate the string at the 255 bytes boundary, but IMHO ellipsis look better as clearly shows the fact of truncation. Now BLR is generated (and later parsed) properly and ellipsis is shown inside the very long plan's alias, AFAIS without any additional side effects.

@dyemanov
Copy link
Member Author

dyemanov commented Apr 2, 2025

The adaptation of plans to the schemas PR was really trick. Maybe you can do the master changes based on it or in the same branch?

No problem. Once approved, I will commit to v5 and delay the master PR until schemas are merged.

void appendContextAlias(DsqlCompilerScratch* dsqlScratch, const string& alias)
{
const auto len = alias.length();
if (len <= MAX_UCHAR)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be more advantageous to use MAX_SQL_IDENTIFIER_LEN rather than MAX_UCHAR, considering the possibility of MetaName length expanding in the future?

Copy link
Member Author

@dyemanov dyemanov Apr 8, 2025

Choose a reason for hiding this comment

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

  1. Alias is a MetaName inside the query, but it's a string for the optimizer (because it's concatenated from the whole aliases stack for nested contexts like derived tables).
  2. String length inside BLR is limited by 1 byte, hence the check for MAX_UCHAR. It would be a PITA to extend it (without introducing new BLR version).

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks for the clarification.

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.

3 participants