-
Notifications
You must be signed in to change notification settings - Fork 22
common: correct the table info when retrieving without virtual columns #1474
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
base: master
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
/test all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @wk989898, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a critical bug in the getColumnSchemaWithoutVirtualColumns
function within pkg/common/table_info_helper.go
. The previous implementation failed to correctly filter and copy non-virtual columns into a new columnSchema
object due to issues with slice initialization and the source of iteration. The changes ensure that the new column schema is properly constructed with only the intended non-virtual columns.
Highlights
- Bug Fix: Column Schema Filtering: I've identified and fixed a logical error in the
getColumnSchemaWithoutVirtualColumns
function. Previously, this function was not correctly populating theColumns
field of the newcolumnSchema
object, leading to an empty or incorrectly filtered list of columns. - Correct Slice Initialization: The
Columns
field of thenewColumnSchema
is now explicitly initialized as a new, empty slice with appropriate capacity (make([]*model.ColumnInfo, 0, len(s.Columns))
). This prevents unintended shallow copying and ensures the slice is ready for independent population. - Accurate Column Iteration: The loop responsible for filtering and adding non-virtual columns now correctly iterates over the original
s.Columns
slice (for _, srcCol := range s.Columns
). This resolves a bug where the loop was incorrectly iterating over the newly created (and empty)newColumnSchema.Columns
, preventing any columns from being added.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR refactors the getColumnSchemaWithoutVirtualColumns
function. While the changes to how the Columns
slice is handled are correct, I've identified a significant bug and a performance issue within the same function that should be addressed. The Indices
slice is being mutated, causing unintended side effects on the original columnSchema
, and the columnsOffset
map is initialized with zero capacity, which is inefficient.
pkg/common/table_info_helper.go
Outdated
@@ -771,7 +771,7 @@ func (s *columnSchema) getColumnList(isUpdate bool) (int, string) { | |||
func (s *columnSchema) getColumnSchemaWithoutVirtualColumns() *columnSchema { | |||
newColumnSchema := &columnSchema{ | |||
Digest: s.Digest, | |||
Columns: s.Columns, | |||
Columns: make([]*model.ColumnInfo, 0, len(s.Columns)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initializing Columns
with a new slice is a good change to prevent aliasing and potential mutations of the original columnSchema
. However, the Indices
field is shallow-copied on the next line (775). Later in the function (lines 805-809), the offsets of index columns are modified. This mutates s.Indices
in the original columnSchema
, which is unexpected for a function with a 'get' prefix and can lead to subtle bugs. To fix this, you should perform a deep copy of s.Indices
before it's modified. Given this is a correctness issue, it's important to address it.
pkg/common/table_info_helper.go
Outdated
rowColumnsCurrentOffset := 0 | ||
columnsOffset := make(map[string]int, len(newColumnSchema.Columns)) | ||
for _, srcCol := range newColumnSchema.Columns { | ||
for _, srcCol := range s.Columns { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to iterate over s.Columns
is correct. However, this change, combined with the change at the start of the function, introduces a performance issue on the preceding line (793). The line columnsOffset := make(map[string]int, len(newColumnSchema.Columns))
now initializes the map with a capacity of 0, because newColumnSchema.Columns
is an empty slice at this point. For better performance, you should initialize the map with an appropriate capacity.
columnsOffset := make(map[string]int, len(s.Columns))
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hongyunyan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
/gemini summary |
Summary of ChangesThis pull request addresses an issue where table information was not being correctly retrieved when virtual columns were excluded. It refactors the code to streamline the process of handling arguments with and without generated columns, ensuring accurate data retrieval and manipulation during database operations. Highlights
Changelog
Activity
|
@wk989898: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: ref #1449
What is changed and how it works?
Removes the BuildTiDBTableInfoWithoutVirtualColumns function since it has no effect.
The generated columns will be skipped when gen SQL in the sqlmodel package.
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note