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

feat: add fields for enhancing global index #297

Closed
wants to merge 1 commit into from

Conversation

L-maple
Copy link

@L-maple L-maple commented Mar 13, 2023

What problem does this PR solve?

Issue Number: ref pingcap/tidb#41991
Issue Number: ref pingcap/tidb#42065

related PR: pingcap/tidb#41992

Problem Summary:

What is changed and how it works?

Proposal: global index

What's Changed:

How it Works:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

@CLAassistant
Copy link

CLAassistant commented Mar 13, 2023

CLA assistant check
All committers have signed the CLA.

@L-maple L-maple force-pushed the feature/enhance_global_index branch from 26ff21b to abd3eac Compare March 13, 2023 09:29
@L-maple
Copy link
Author

L-maple commented Mar 14, 2023

/cc @mjonss

@@ -154,6 +154,8 @@ message IndexScan {
optional bool desc = 4 [(gogoproto.nullable) = false];
optional bool unique = 5; // check whether it is a unique index.
repeated int64 primary_column_ids = 6;
optional bool is_global = 7; // check whether it is a global index.

Choose a reason for hiding this comment

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

Can you briefly explain why these two parameters are added?

And I think you should also modify its related logic on the TiKV side.

Copy link
Author

Choose a reason for hiding this comment

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

is_global means whether it is a global index. Only when is_global is true, we should consider partition_ids. TiKV then filters out the rows by comparing partition_ids and PartitionID in index value.

For global index, Not all indexes' row should be returned when partitions are specified or some partitions are in reorg.
e.g., select * from pt partition(p0) use index(global_idx); The IndexScan DAG should contain p0 to filter the needed partitions' rows.
e.g., pt has p0,p1,p2 partitions. When p0 is in reorg, its index rows should not be queried.

In summary, necessary info should be contained in the IndexScan, so that TiKV can handle these circumstances correctly.

Copy link
Author

Choose a reason for hiding this comment

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

OK, I will propose the PR for TiKV, and mention the PR here.

But please review this PR first, so that this tipb PR can be used in TiDB PR. Then the TiDB PR can be tested.

Copy link

Choose a reason for hiding this comment

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

Is it possible to use a Selection instead of combining an Index Scan with a filter/selection? I.e. do we need to add this PR?

Copy link
Author

Choose a reason for hiding this comment

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

@mjonss Aha, it's a really nice idea. But it is really difficult for me in two aspects:

  1. What conditions I should put into Selection. Because ExtraPartitionID is not a real column.
  2. When I should construct the Selection.

Copy link

Choose a reason for hiding this comment

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

I'm OK in doing the filtering in TiDB for now and postpone the optimization of pushing down the filtering to a future PR. I just don't think we should change tipb repo like this, since I think the current protocol already have a more generic way of solving this.

Copy link
Author

@L-maple L-maple Mar 17, 2023

Choose a reason for hiding this comment

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

@mjonss @Defined2014 OK, I agree to postpone the optimization.

But I have to say the disadvantages:

  1. the code is really ugly in some places if partitionIds not pushed down.
  2. @mjonss How should I handle this case: [IndexScan(cop) <- HashAgg(cop) <- IndexReader(root)]. If partitionIds not pushed down, Agg also not allowed pushed down. Otherwise, the result is wrong.

Copy link
Author

@L-maple L-maple Mar 17, 2023

Choose a reason for hiding this comment

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

@mjonss I remove the push down logic in TiDB PR, but remain related unit tests. This optimization(or fix) can be realized in future.

Copy link
Contributor

@windtalker windtalker Mar 17, 2023

Choose a reason for hiding this comment

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

I aggree that ExtraPartitionID should be treated as a normal column, and I think it is not a big problem about when/how to construct the selection, you can always contruct the filter/selection when your current code is setting is_global_index and partition_ids. There might be one benifit by putting is_global_index/partition_ids inside index scan: the index scan itself can skip some blocks based on these information. But for a well designed compiler, it should support push down filter to scan(not sure if TiKV support this)

Copy link
Author

Choose a reason for hiding this comment

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

@windtalker OK, I will consider your advice and propose a new PR in future.

This PR can be closed.

@L-maple L-maple requested a review from mjonss March 17, 2023 03:53
@L-maple
Copy link
Author

L-maple commented Mar 20, 2023

/close

2 similar comments
@L-maple
Copy link
Author

L-maple commented Mar 20, 2023

/close

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

/close

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

/close not-planned

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

/assign @L-maple

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

/close

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

/close not-planned

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

@Defined2014 Hi, how could I close this PR? /close seems not function.

@Defined2014
Copy link

Do you have permission to press the close pull button?
image

@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

/close

@L-maple L-maple closed this Nov 15, 2023
@L-maple
Copy link
Author

L-maple commented Nov 15, 2023

Do you have permission to press the close pull button? image

Oh, I find it! Thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants