Skip to content

Fixing bug with handling output columns - MySql#1647

Merged
ayush3797 merged 5 commits intomainfrom
dev/agarwalayush/bugWithHandlingOutputColumnsMySql
Aug 24, 2023
Merged

Fixing bug with handling output columns - MySql#1647
ayush3797 merged 5 commits intomainfrom
dev/agarwalayush/bugWithHandlingOutputColumnsMySql

Conversation

@ayush3797
Copy link
Copy Markdown
Contributor

@ayush3797 ayush3797 commented Aug 23, 2023

Why make this change?

Fix #1648

Currently Output columns are incorrectly handled while generating SELECT query for MySql after update via UPSERT operation.
Relevant code snippet:
image
Link to file:

selections.Add($"{structure.Values[index]} AS {quotedColName}");

Where is the bug?
As we can observe that in the attached code snippet, we are processing the output columns one by one. The IF block for line 293 is hit when we find a column which is present in the structure.InsertColumns. We add such a column to the final selections and increment the index:

selections.Add($"{structure.Values[index]} AS {quotedColName}");
index++;

What have we assumed here?
We have assumed that the order of columns in structure.InsertColumns is same as structure.OutputColumns. Well that is certainly not true as output columns can have columns other that insertColumns and even if the columns are same, the order can differ. So, we cannot just reference structure.Values[index] on line 293 and increment the index on line 294.. We need to be sure that this output column, which is also an insert column, corresponds to this parameter name at structure.Values[index] (structure.Values essentially stores parameter names for each of the insert columns).

What is this change?

  • Instead of incrementing index, we need a dictionary insertColumnsToParamName which certainly tells us as to what paramName does each of the insertColumns map to. This also prevents an O(n) lookup that we were doing to check if the output column is present in the list of structure.InsertColumns.

How was this tested?

Will be adding tests in: #1596, if required at all. The existing tests are still passing which confirms the change is good.

@ayush3797 ayush3797 self-assigned this Aug 23, 2023
@ayush3797 ayush3797 added bug Something isn't working mysql an issue thats specific to mysql labels Aug 23, 2023
@ayush3797 ayush3797 linked an issue Aug 23, 2023 that may be closed by this pull request
@ayush3797 ayush3797 marked this pull request as ready for review August 23, 2023 14:37
Comment thread src/Core/Resolvers/MySqlQueryBuilder.cs Outdated
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks for fixing this!

@ayush3797 ayush3797 enabled auto-merge (squash) August 24, 2023 06:52
@ayush3797 ayush3797 merged commit ecc0778 into main Aug 24, 2023
@ayush3797 ayush3797 deleted the dev/agarwalayush/bugWithHandlingOutputColumnsMySql branch August 24, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mysql an issue thats specific to mysql

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Output columns incorrectly processed for MySql

3 participants