-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
planner/core: define extractor for each schema related memtables #55144
Conversation
Hi @tangenta. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. 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. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #55144 +/- ##
================================================
+ Coverage 72.8978% 73.4966% +0.5987%
================================================
Files 1569 1570 +1
Lines 439212 440242 +1030
================================================
+ Hits 320176 323563 +3387
+ Misses 99399 96693 -2706
- Partials 19637 19986 +349
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
2 / 7 files viewed
pkg/executor/infoschema_reader.go
Outdated
continue | ||
} | ||
tables, err := e.is.SchemaTableInfos(ctx, schema) | ||
tables, err := ex.ListTables(ctx, e.is, schema) |
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.
Why ListTables?
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.
here List
... does not mean full scan tables. It will filter with ex
's predicates. Maybe rename it?
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.
Do you have any suggestions for naming?
It is actually "list part of tables if predicate exists, otherwise list all tables".
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.
How about FilterSchemas
FilterTables
?
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.
Do you mean FilteredSchema
and FilteredTables
?
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.
5 / 7 files viewed
if !ok { | ||
continue | ||
} | ||
_, err := is.TableByName(ctx, schema, tbl.Meta().Name) |
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.
Why checking the name here?
return | ||
ex, ok := e.extractor.(*plannercore.InfoSchemaSchemataExtractor) | ||
if !ok { | ||
return errors.Errorf("wrong extractor type: %T, expected InfoSchemaSchemataExtractor", e.extractor) |
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.
Do we have tests to cover such case? If no, if plannercore change it, there is no way to found.
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.
pkg/executor/infoschema_reader.go
Outdated
continue | ||
} | ||
tables, err := e.is.SchemaTableInfos(ctx, schema) | ||
tables, err := ex.ListTables(ctx, e.is, schema) |
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.
How about FilterSchemas
FilterTables
?
[LGTM Timeline notifier]Timeline:
|
@tangenta: 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. |
} | ||
r := new(bytes.Buffer) | ||
colNames := make([]string, 0, len(e.ColPredicates)) | ||
for colName := range e.ColPredicates { |
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.
maps.Keys()
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.
} | ||
|
||
// ExplainInfo implements base.MemTablePredicateExtractor interface. | ||
func (e *InfoSchemaBaseExtractor) ExplainInfo(_ base.PhysicalPlan) string { |
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.
I'm not sure what's the expected behaviour of ExplainInfo
because the comments are poor. Should it be the used filter for a query rather than all filters?
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.
Yes. For unused filters, they will be displayed as another operator. For example:
mysql> explain select * from information_schema.tables where (table_name = 't2' and tidb_table_id = 3);
+----------------+----------+------+---------------+----------------------------------------+
| id | estRows | task | access object | operator info |
+----------------+----------+------+---------------+----------------------------------------+
| MemTableScan_5 | 10000.00 | root | table:TABLES | table_name:["t2"], tidb_table_id:["3"] |
+----------------+----------+------+---------------+----------------------------------------+
1 row in set (0.00 sec)
mysql> explain select * from information_schema.tables where table_name = 't1' or (table_name = 't2' and tidb_table_id = 3);
+----------------------+----------+------+---------------+-------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------+----------+------+---------------+-------------------------------------------------------------------+
| Selection_5 | 8000.00 | root | | or(eq(Column#3, "t1"), and(eq(Column#3, "t2"), eq(Column#22, 3))) |
| └─MemTableScan_6 | 10000.00 | root | table:TABLES | |
+----------------------+----------+------+---------------+-------------------------------------------------------------------+
2 rows in set (0.00 sec)
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.
it's OK to merge this PR and fix my comments in future.
if !ok { | ||
continue | ||
} | ||
if len(tableNames) > 0 && containInTableNames(tableNames, tbl) { |
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.
maybe use map type for tableNames
, to implement O(1) containInTableNames
.
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.
tableMap := make(map[int64]schemaAndTable, len(tableNames)) | ||
for _, n := range tableNames { | ||
for _, s := range schemas { | ||
tbl, err := is.TableByName(ctx, s, n) |
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.
I see at least in infoschema v2 when we get the table we already know its db (tableItem
has associated all related information together). So there's a potential optimization to skip the TableByName
.
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.
Maybe we can add more methods for infoschema v2 later.
2b70976
to
05c4815
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AilinKid, tiancaiamao, wjhuang2016 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 |
What problem does this PR solve?
Issue Number: ref #50305
Problem Summary:
What changed and how does it work?
infoschema.TableSchemata
andinfoschema.TableStatistics
.InfoSchemaTablesExtractor
toInfoSchemaBaseExtractor
, and embed it into following extractors:InfoSchemaTablesExtractor
InfoSchemaPartitionsExtractor
InfoSchemaStatisticsExtractor
InfoSchemaSchemataExtractor
ListSchemas()
andListTables()
for previous extractors.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.