Skip to content

Fix select for update retry - #10102

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
zhangxu19830126:fix_select_for_update_retry
Jun 17, 2023
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
zhangxu19830126:fix_select_for_update_retry

Conversation

@zhangxu19830126

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #5004

What this PR does / why we need it:

Let the lock operator support select for update. For select for update, the query cannot be executed until all the locks on the query rows are completed. Because in case of a conflict, RC mode requires seeing the latest result and retrying. If the query is executed before all locks are completed, the client will receive the wrong data

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jun 16, 2023
@mergify mergify Bot added the kind/feature label Jun 16, 2023
@matrix-meow

Copy link
Copy Markdown
Contributor

@zhangxu19830126 Thanks for your contributions!

Here are review comments for file pkg/pb/plan/plan.pb.go:
Unfortunately, there is no actual code changes in this pull request. The title and body suggest that there is a fix for a select for update retry issue, but there are no changes in the code. Therefore, the pull request needs to be closed or updated with the actual code changes. If there are actual code changes, the pull request should include a detailed description of the changes made, why they were necessary, and how they address the issue. Additionally, the pull request should include any relevant tests to ensure that the changes do not introduce new issues.

Here are review comments for file pkg/sql/colexec/lockop/lock_op.go:
The pull request aims to add support for select for update in the lock operator. The changes include adding a new state struct, state, to store the state of the lock operator, and modifying the Call function to handle blocking and non-blocking cases.

However, there are several issues with this pull request that need addressing:

  1. The title of the pull request is not descriptive enough. It should include more information about what the pull request is trying to accomplish, such as "Add support for select for update in lock operator".

  2. The body of the pull request is incomplete. It should include more information about the changes made, why they were made, and how they improve the codebase.

  3. The changes made in the pull request are not optimized. The Call function is now longer and more complex, which could make it harder to maintain in the future. It would be better to break it down into smaller, more manageable functions.

  4. The code is not well-documented. There are no comments explaining what the code is doing or why it is necessary. This could make it difficult for other developers to understand the code and make changes in the future.

  5. There are several typos and formatting issues in the code, such as misspelling "table" as "tabel" and inconsistent indentation.

Here are review comments for file pkg/sql/colexec/lockop/types.go:
The pull request adds support for select for update to the lock operator. The changes include modifying the FetchLockRowsFunc to support select for update, adding a new field to the Argument struct, and introducing a new state struct.

There are a few issues with this pull request that need addressing:

  1. The title of the pull request is not descriptive enough. It simply states "Fix select for update retry" without providing any context or information about what the fix is addressing. A more descriptive title would be helpful for reviewers to understand the purpose of the pull request.

  2. The body of the pull request is incomplete. It includes a checklist of PR types and a reference to the issue being fixed, but it does not provide any additional information about the changes being made or why they are necessary. A more detailed description of the changes and their purpose would be helpful for reviewers.

  3. There are several typos and inconsistencies in the code changes. For example, "hodler" should be "holder", "lockTabel" should be "lockTable", and "fliterCols" should be "filterCols". These should be corrected to improve the readability and maintainability of the code.

  4. The new state struct introduced in the changes is not well-documented. It is unclear what its purpose is and how it is used. Adding comments or documentation to explain its role would be helpful for future maintainers of the code.

To optimize the changes made in the pull request, the author could consider providing more detailed comments and documentation to explain the purpose and usage of the modified code. Additionally, they could consider adding test cases to ensure that the new functionality works as expected and does not introduce any regressions.

Here are review comments for file pkg/sql/compile/compile.go:
The pull request aims to fix the select for update retry issue. The changes made in the pull request include adding support for the lock operator to select for update, which ensures that the query is not executed until all the locks on the query rows are completed. The changes also include modifying the instructions for the lock operator to handle the block flag.

However, the pull request lacks a detailed explanation of the problem that the changes aim to solve. It would be helpful to provide more information on the issue and its impact on the codebase. Additionally, the pull request does not include any tests to ensure that the changes do not introduce new issues. It would be best to include tests to validate the changes and ensure that they work as expected.

Regarding the changes, it would be better to refactor the code to make it more readable and maintainable. For instance, the if-else block can be simplified by extracting the common code outside the block. This will make the code easier to read and reduce the chances of introducing bugs.

Finally, the pull request should follow the project's guidelines for formatting, naming conventions, and documentation. This will ensure that the codebase remains consistent and easy to maintain.

Here are review comments for file pkg/sql/compile/operator.go:
The pull request titled "Fix select for update retry" aims to add support for select for update in the lock operator. The body of the pull request mentions that this change is necessary because the query cannot be executed until all the locks on the query rows are completed. The changes made in the file pkg/sql/compile/operator.go include adding a new line of code to set the block for the argument.

However, there are a few issues with this pull request that need to be addressed:

  1. Lack of context: The pull request does not provide enough context about the problem it is trying to solve. It would be helpful to include more information about the issue that was encountered and how this change addresses it.

  2. Incomplete description: The pull request description is incomplete and does not provide a clear explanation of what the change does. It would be helpful to include more details about the changes made and how they affect the codebase.

  3. Lack of testing: The pull request does not include any tests to ensure that the changes made do not introduce new bugs or issues. It would be helpful to include tests that cover the new functionality added.

To optimize the changes made in the pull request, the following suggestions can be considered:

  1. Provide more context: The pull request should include more information about the issue that was encountered and how this change addresses it. This will help reviewers understand the problem and evaluate the proposed solution more effectively.

  2. Improve the description: The pull request description should be improved to provide a clear explanation of what the change does. This will help reviewers understand the changes made and how they affect the codebase.

  3. Include tests: The pull request should include tests that cover the new functionality added. This will help ensure that the changes made do not introduce new bugs or issues.

Overall, while the change proposed in the pull request may be necessary, it is important to provide more context and testing to ensure that it is implemented correctly and does not introduce new issues.

Here are review comments for file pkg/sql/compile/scopeRemoteRun.go:
The pull request seems to fix an issue with the lock operator in the SQL compiler. The changes made in the scopeRemoteRun.go file add support for select for update queries, ensuring that the query is not executed until all locks on the query rows are completed.

However, there are a few issues with the pull request that need addressing:

  1. The title of the pull request is not descriptive enough. It simply states "Fix select for update retry" without providing any context or information about the issue being fixed. A more descriptive title would be helpful for reviewers to understand the purpose of the pull request.

  2. The body of the pull request is incomplete. It only includes a checklist of PR types and a reference to the issue being fixed. It would be helpful to include more information about the issue, such as how it was discovered and any potential impact it may have had on the codebase.

  3. The changes made in the scopeRemoteRun.go file are not optimized. The addition of the Block field to the LockOp struct seems unnecessary, as it is not used anywhere else in the codebase. Removing this field would simplify the code and make it easier to maintain.

To address these issues, the pull request should be updated with a more descriptive title and a more detailed body that explains the issue being fixed and how it was discovered. Additionally, the changes made in the scopeRemoteRun.go file should be optimized by removing the Block field from the LockOp struct.

Here are review comments for file pkg/sql/plan/query_builder.go:
The pull request title "Fix select for update retry" is clear and concise, indicating that the changes address a specific issue related to retrying a select for update query. However, the body of the pull request is not very informative. It only lists the issue number that the pull request fixes and provides a brief explanation of what the changes do. It would be helpful to have more context on the issue and why the changes are necessary.

The changes made in the pull request modify the QueryBuilder function in the pkg/sql/plan/query_builder.go file. Specifically, a new Block field is added to the TableAccessNode struct, which is set to true when a select for update query is executed. This change ensures that the query is not executed until all the locks on the query rows are completed, which is necessary for retrying in case of a conflict.

One potential problem with the changes is that the RefreshTsIdxInBat and FilterColIdxInBat fields are set to -1, indicating that they are not supported. It is not clear why these fields are not supported or if there are any implications for not supporting them. It would be helpful to have more information on this.

Another potential issue is that the pull request does not include any tests or documentation. It is important to ensure that the changes are thoroughly tested and that any necessary documentation is updated to reflect the changes.

To optimize the changes, it may be helpful to provide more detailed comments explaining the purpose and functionality of the new Block field. Additionally, it may be beneficial to refactor the code to make it more modular and easier to read. Finally, it would be helpful to include tests that cover all possible scenarios and edge cases to ensure that the changes are robust and reliable.

Here are review comments for file proto/pipeline.proto:
The title of the pull request is clear and concise. The body of the pull request provides some context about the changes made and the reason for making them. However, it could be improved by providing more details about the changes made and how they address the issue.

The changes made in the pull request are focused on adding support for select for update in the lock operator. The changes involve adding a new boolean field "block" to the LockOp message in the pipeline.proto file.

One potential problem with the changes is that they may not be optimized for performance. The addition of the "block" field may introduce additional overhead and slow down the lock operator. It would be helpful to have some performance benchmarks to ensure that the changes do not have a negative impact on performance.

Another issue with the pull request is that it lacks sufficient testing. It would be helpful to have unit tests that cover the new functionality added by the changes. This would ensure that the changes work as intended and do not introduce any new bugs.

To address these issues, the pull request could be updated to include more details about the changes made and how they address the issue. Additionally, performance benchmarks and unit tests could be added to ensure that the changes are optimized and do not introduce new bugs.

Here are review comments for file proto/plan.proto:
The pull request title and body are clear and provide useful information about the changes being made. However, there are a few issues with the changes made in the pull request that need to be addressed:

  1. The changes made in the pull request are not explained in detail. It is unclear what the "lock operator" is and how it supports "select for update". Providing more information about the changes made and their purpose would make it easier for other developers to understand and review the code.

  2. The changes made in the pull request are not optimized. The addition of a new boolean field "block" to the LockTarget message could potentially cause compatibility issues with existing code that uses this message. It would be better to find a way to modify the existing fields to support the new functionality instead of adding a new field.

  3. The pull request does not include any tests or documentation. It is important to include tests to ensure that the changes made do not introduce new bugs or regressions. Additionally, documentation should be provided to explain how to use the new functionality and any potential caveats or limitations.

To address these issues, the pull request author should provide more detailed information about the changes made and their purpose. They should also consider modifying the existing fields instead of adding a new one to avoid compatibility issues. Finally, tests and documentation should be added to ensure that the changes are properly tested and documented.

@mergify
mergify Bot merged commit b15303a into matrixorigin:main Jun 17, 2023
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
Let the lock operator support select for update. For select for update, the query cannot be executed until all the locks on the query rows are completed. Because in case of a conflict, RC mode requires seeing the latest result and retrying. If the query is executed before all locks are completed, the client will receive the wrong data

Approved by: @ouyuanning, @m-schen, @nnsgmsone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants