Skip to content

Make parameter length based on underlying column length except for complex ops#2627

Open
simonsabin wants to merge 18 commits intoAzure:mainfrom
simonsabin:paramlength
Open

Make parameter length based on underlying column length except for complex ops#2627
simonsabin wants to merge 18 commits intoAzure:mainfrom
simonsabin:paramlength

Conversation

@simonsabin
Copy link
Collaborator

@simonsabin simonsabin commented Mar 20, 2025

Why make this change?

Closes #2626

What is this change?

Where a parameter is linked to an underlying column in the data model the length is stored
When the query is executed the length is used to ensure parameters have consistent lengths

For certain operations the value is padded with escape characters or %s, these need to be allowed for. In those cases the length is set to -1 (max) in order that the extra characters are allowed for AND consistent lengths are maintained

How was this tested?

  • Integration Tests

Checking the resultant query is using the right length was done using trace. Not sure with the architecture whether it would be possible to mock at that level.

Sample Request(s)

See new tests TestFilterParamForStringFilterWorkWithComplexOp and TestFilterParamForStringFilterWorkWithNotContains

Copy link
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

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

This looks great, thank you for raising and then solving this issue. Just had a few nits, and a question.

@simonsabin
Copy link
Collaborator Author

simonsabin commented Mar 20, 2025 via email

simonsabin and others added 2 commits March 20, 2025 21:53
Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>
Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>
@simonsabin
Copy link
Collaborator Author

applied suggested changes

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle
Copy link
Contributor

Pipeline failures are just whitespace format.

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates MSSQL parameter creation to stabilize query plan reuse by sizing string parameters based on underlying column length, with an escape hatch for “complex” string operations that expand values (LIKE patterns/escaping).

Changes:

  • Capture MSSQL column length in SQL metadata (ColumnSize) and flow it through DbConnectionParam.
  • Extend parameterization to support a lengthOverride path (intended for LIKE-based operations).
  • Add/adjust MSSQL GraphQL tests and MSSQL test schema to exercise string filter scenarios.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs Adds new GraphQL filter tests for string params (simple and complex ops).
src/Service.Tests/DatabaseSchema-MsSql.sql Changes books.title to varchar(30) and adjusts seed data to include a special character.
src/Core/Services/MetadataProviders/SqlMetadataProvider.cs Populates column length for MSSQL columns via schema metadata.
src/Core/Resolvers/MsSqlQueryExecutor.cs Sets SqlParameter.Size for certain string SqlDbTypes based on new length metadata.
src/Core/Resolvers/CosmosQueryStructure.cs Updates MakeDbConnectionParam signature to include lengthOverride for parity with base.
src/Core/Resolvers/BaseQueryStructure.cs Adds lengthOverride argument and flows parameter length from model metadata into DbConnectionParam.
src/Core/Models/GraphQLFilterParsers.cs Plumbs lengthOverride through GraphQL filter parsing for LIKE-based operators.
src/Core/Models/DbConnectionParam.cs Adds Length to represent intended parameter size.
src/Config/DatabasePrimitives/DatabaseObject.cs Adds GetLengthForParam and stores ColumnDefinition.Length.

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle aaronburtle added the 2.0 label Mar 6, 2026
@aaronburtle aaronburtle moved this from Todo to Review In Progress in Data API builder Mar 6, 2026
@aaronburtle aaronburtle modified the milestones: Backlog, March 2026 Mar 6, 2026
@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@simon-sabin-BE
Copy link

thanks for perservering with this

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 cri Customer Reported issue

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

For MSSQL Parameters are created with length based on their value not the underlying model length this causes plan reuse issues

6 participants