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

Choose the better unique index #50184

Closed
elsa0520 opened this issue Jan 8, 2024 · 0 comments · Fixed by #50185 or #50262
Closed

Choose the better unique index #50184

elsa0520 opened this issue Jan 8, 2024 · 0 comments · Fixed by #50185 or #50262

Comments

@elsa0520
Copy link
Contributor

elsa0520 commented Jan 8, 2024

Enhancement

If both of unique index need to double scan, we should better choose the unique index which can match all of where predicates.
The reason is that if the unique index can match the all of where predicates, it will skip the double scan when the qualify row is zero.

For example

  1. create table
CREATE TABLE t ( a int NOT NULL ,  b int NOT NULL,
			c varchar(64) NOT NULL ,  d varchar(64) NOT NULL  ,
			UNIQUE KEY ua (a),
			UNIQUE KEY uab (a, b));
  1. query
select * from t where a=1 and b=1;
  1. choose the uab index

uab index is better than ua. When there is no row can match the where predicates "a=1 and b=1", the uab index can skip the double scan while the ua index can not.

"Point_Get 1.00 root table:t, index:uab(a, b) "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant