Skip to content
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

Merged
merged 21 commits into from
Aug 6, 2024

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Aug 1, 2024

What problem does this PR solve?

Issue Number: ref #50305

Problem Summary:

What changed and how does it work?

  • Add extractor for infoschema.TableSchemata and infoschema.TableStatistics.
  • Rename previous InfoSchemaTablesExtractor to InfoSchemaBaseExtractor, and embed it into following extractors:
    • InfoSchemaTablesExtractor
    • InfoSchemaPartitionsExtractor
    • InfoSchemaStatisticsExtractor
    • InfoSchemaSchemataExtractor
  • Provide ListSchemas() and ListTables() for previous extractors.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/planner SIG: Planner labels Aug 1, 2024
Copy link

tiprow bot commented Aug 1, 2024

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 77.09751% with 101 lines in your changes missing coverage. Please review.

Project coverage is 73.4966%. Comparing base (5aad7df) to head (58cabe9).
Report is 2 commits behind head on master.

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     
Flag Coverage Δ
integration 22.5040% <21.7687%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 46.1692% <ø> (+0.2670%) ⬆️

Copy link
Contributor

@lance6716 lance6716 left a 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/planner/core/memtable_infoschema_extractor.go Outdated Show resolved Hide resolved
pkg/planner/core/memtable_infoschema_extractor.go Outdated Show resolved Hide resolved
continue
}
tables, err := e.is.SchemaTableInfos(ctx, schema)
tables, err := ex.ListTables(ctx, e.is, schema)
Copy link
Member

Choose a reason for hiding this comment

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

Why ListTables?

Copy link
Contributor

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?

Copy link
Contributor Author

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".

Copy link
Contributor

Choose a reason for hiding this comment

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

How about FilterSchemas FilterTables ?

Copy link
Contributor Author

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?

Copy link
Contributor

@lance6716 lance6716 left a 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

pkg/executor/infoschema_reader.go Outdated Show resolved Hide resolved
pkg/planner/core/memtable_infoschema_extractor.go Outdated Show resolved Hide resolved
if !ok {
continue
}
_, err := is.TableByName(ctx, schema, tbl.Meta().Name)
Copy link
Member

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

continue
}
tables, err := e.is.SchemaTableInfos(ctx, schema)
tables, err := ex.ListTables(ctx, e.is, schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about FilterSchemas FilterTables ?

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 2, 2024
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 3, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 5, 2024
Copy link

ti-chi-bot bot commented Aug 5, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-02 10:31:05.25556504 +0000 UTC m=+2395.122664139: ☑️ agreed by tiancaiamao.
  • 2024-08-05 08:11:22.734339757 +0000 UTC m=+253212.601438837: ☑️ agreed by wjhuang2016.

Copy link

tiprow bot commented Aug 5, 2024

@tangenta: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow 42198b3 link true /test fast_test_tiprow

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

maps.Keys()

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

@lance6716 lance6716 left a 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

@lance6716 lance6716 Aug 5, 2024

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.

Copy link
Contributor Author

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.

Copy link

ti-chi-bot bot commented Aug 6, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Aug 6, 2024
@ti-chi-bot ti-chi-bot bot merged commit 07c35e8 into pingcap:master Aug 6, 2024
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants