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

*: update extractor for tidb_index_usage and columns table #55263

Merged
merged 15 commits into from
Aug 14, 2024

Conversation

joechenrh
Copy link
Contributor

@joechenrh joechenrh commented Aug 7, 2024

What problem does this PR solve?

Issue Number: ref #50305

Problem Summary:

What changed and how does it work?

Like #55144, this PR adds InfoSchemaTableNameExtractor to extract schemas, tables and like operators from predicates, and embed it into following extractors:

  • InfoSchemaIndexesExtractor, which is used for infoschema.TableTiDBIndexUsage
  • ColumnsTableExtractor, which is used for infoschema.TableColumns

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.

Create about 20w tables

mysql> select count(*) from information_schema.tables where table_schema = "test";
+----------+
| count(*) |
+----------+
|   202823 |
+----------+

Before and after:

mysql> select table_name, column_name from information_schema.columns where table_name = "t10000";
+------------+-------------+
| table_name | column_name |
+------------+-------------+
| t10000     | id          |
| t10000     | col1        |
| t10000     | col2        |
+------------+-------------+
3 rows in set (5.65 sec)

mysql> select table_name, column_name from information_schema.columns where table_name = "t10000";
+------------+-------------+
| table_name | column_name |
+------------+-------------+
| t10000     | id          |
| t10000     | col1        |
| t10000     | col2        |
+------------+-------------+
3 rows in set (0.00 sec)

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 7, 2024
Copy link

tiprow bot commented Aug 7, 2024

Hi @joechenrh. 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.

@joechenrh
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked labels Aug 7, 2024
Copy link

codecov bot commented Aug 7, 2024

Codecov Report

Attention: Patch coverage is 86.69528% with 31 lines in your changes missing coverage. Please review.

Project coverage is 74.7655%. Comparing base (7e9f853) to head (cf0931c).
Report is 10 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55263        +/-   ##
================================================
+ Coverage   72.9185%   74.7655%   +1.8470%     
================================================
  Files          1576       1576                
  Lines        440552     440707       +155     
================================================
+ Hits         321244     329497      +8253     
+ Misses        99560      90975      -8585     
- Partials      19748      20235       +487     
Flag Coverage Δ
integration 49.1426% <80.2575%> (?)
unit 71.8571% <86.6952%> (-0.1170%) ⬇️

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

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

@D3Hunter
Copy link
Contributor

D3Hunter commented Aug 7, 2024

What changed and how does it work?

please add more detail on what you have done. and why you do that, if it's for optimize, what's test result?

@joechenrh joechenrh changed the title planner/core: update extractor for tidb_index_usage and columns table *: update extractor for tidb_index_usage and columns table Aug 13, 2024
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 13, 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 13, 2024
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 13, 2024
@tangenta tangenta requested a review from AilinKid August 13, 2024 09:59

idxs := extractor.ListIndexes(tbl)
for _, idx := range idxs {
row := make([]types.Datum, 0, 14)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it support the index_name filter?

Copy link
Contributor

Choose a reason for hiding this comment

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

select ... from index_usage where table_schema = 'xxx' and index_name = 'yyy'

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, it does.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, it's inside the ListIndexes() function.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 14, 2024
Copy link

ti-chi-bot bot commented Aug 14, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-13 07:52:52.847522933 +0000 UTC m=+254457.550992576: ☑️ agreed by tangenta.
  • 2024-08-14 01:18:40.927626606 +0000 UTC m=+317205.631096265: ☑️ agreed by tiancaiamao.

pkg/table/tables/tables_test.go Show resolved Hide resolved
if column.Hidden {
continue
}
ord++
Copy link
Contributor

Choose a reason for hiding this comment

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

should we move ord++ to L890, and let it increase the same pace with appending columns, otherwise, your ord and columns are not with the same length (max ord != len(columns)-1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ord is the ordinal positions of columns in tables, so it should increase for every non hidden column. Here is the logic before the modification:

i := 0
ForColumnsTag:
for _, col := range tbl.Columns {
if col.Hidden {
continue
}
i++

Copy link
Contributor

@AilinKid AilinKid Aug 14, 2024

Choose a reason for hiding this comment

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

i can get your code block, is this (max ord != len(columns)-1)? reasonable ?

Copy link
Contributor

@tangenta tangenta Aug 14, 2024

Choose a reason for hiding this comment

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

@AilinKid Yes.

ORDINAL_POSITION

The position of the column within the table. ORDINAL_POSITION is necessary because you might want to say ORDER BY ORDINAL_POSITION

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, since predicates may filter out some columns. And this value is the original position in the table.

Copy link
Contributor

Choose a reason for hiding this comment

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

soga, okok

Copy link

ti-chi-bot bot commented Aug 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, tangenta, tiancaiamao

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 14, 2024
@ti-chi-bot ti-chi-bot bot merged commit cfcd164 into pingcap:master Aug 14, 2024
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. 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