-
Notifications
You must be signed in to change notification settings - Fork 6k
distsql: Add SelectResultIter
to read rows from cop-task in the iterator way
#63319
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
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #63319 +/- ##
================================================
+ Coverage 72.7739% 73.2773% +0.5033%
================================================
Files 1832 1832
Lines 495728 497881 +2153
================================================
+ Hits 360761 364834 +4073
+ Misses 113021 111165 -1856
+ Partials 21946 21882 -64
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
/retest |
614903c
to
ab13c1f
Compare
@@ -381,6 +415,16 @@ func (r *selectResult) fetchResp(ctx context.Context) error { | |||
if err != nil { | |||
return errors.Trace(err) | |||
} | |||
|
|||
if len(r.selectResp.IntermediateOutputs) != len(intermediateOutputTypes) { | |||
return errors.Errorf( |
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.
Does it indicates inconsistency? If so the inconsistencyReporter
could be used to log necessary information.
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.
This situation should never happen, but it has no relationship with the data consistency. If it happens, it is more like the TiDB or TiKV code has a bug that makes the wrong assumption of the data channels.
c7c122c
to
c77a2e1
Compare
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.
Pull Request Overview
This PR introduces a new SelectResultIter
interface that enables reading rows from coprocessor tasks in an iterator-based manner, supporting multiple output channels from cop-task responses. This change accommodates scenarios where cop-task responses contain multiple output channels (such as push-down IndexLookup executors) with different schemas per channel.
Key changes:
- Added
SelectResultIter
interface withNext()
andClose()
methods for iterating over rows - Introduced
SelectResultRow
struct to encapsulate row data with a channel identifier - Implemented channel-based iteration logic to handle intermediate outputs from coprocessor responses
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pkg/distsql/select_result.go | Core implementation of SelectResultIter interface and channel-based row iteration logic |
pkg/distsql/select_result_test.go | Comprehensive test coverage for the new iterator functionality and channel handling |
pkg/executor/table_readers_required_rows_test.go | Added stub implementation of IntoIter method to maintain interface compatibility |
pkg/distsql/distsql_test.go | Enhanced mock infrastructure to support intermediate outputs testing |
pkg/distsql/BUILD.bazel | Increased test shard count to accommodate additional test cases |
go.mod, DEPS.bzl | Updated tipb and other dependencies to support new features |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
/retest |
1 similar comment
/retest |
} | ||
|
||
func newSelRespChannelIter(result *selectResult, channel int) (*selRespChannelIter, error) { | ||
intest.Assert(result != nil && result.selectResp != nil && len(result.selectResp.IntermediateOutputs) == len(result.intermediateOutputTypes)) |
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.
Should we return an error in production?
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.
This is an internal call, and some conditions have been checked outside: https://github.com/pingcap/tidb/pull/63319/files#diff-f45688fe21dcc5e4a40e356dc44d0fe3622a8557ac3f8e58ce6d86d3efc0ed43R425
Seems it's more simple to just use an assert
// `Channel` indicates the index where this row locates. | ||
// When Channel < len(IntermediateChannels), it means this row is from intermediate result. | ||
// Otherwise, if Channel == len(IntermediateChannels), it means this row is from final result. | ||
Channel int |
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.
Channel int | |
ChannelIndex int |
Seems better.
// some intermediate output contains data, | ||
// we should return the response even if the main output is empty. | ||
return nil | ||
} |
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.
Is it expected to contain zero lengh chunk in the IntermediateOutputs
results? If not should we add assertions here too?
What problem does this PR solve?
Issue Number: close #63318
Problem Summary:
After pingcap/tipb#376 is merged, the cop-task response may contain multiple output channels (i.e., the push down IndexLookup executor), and each of these channels may have a different kind of schema.
SelectResult
should support reading the results from multiple channels.What changed and how does it work?
SelectResultIter
is provided.SelectResultIter
is defined as:The
Next
is used to read the rows from the cop-task.SelectResultRow
contains an extra fieldChannel
to indicate where the row is from:Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.