How to have a covering index used for the updates?
0
votes
2
answers
63
views
I have a db table with"
-
id bigint NOT NULL AUTO_INCREMENT
(primary key)
- customer_ref varchar(64) NOT NULL
- customer_counter int NOT NULL
- description varchar(255) NOT NULL
I have also the following indexes:
- PRIMARY KEY(id)
- UNIQUE KEY c_ref (customer_ref)
- KEY c_c (customer_counter)
- KEY c_desc(customer_ref, description, customer_counter)
I have the following update statements:
UPDATE CustomerReferences SET customer_counter=100, description='invalidate due to X123' WHERE customer_ref='1000001' and description 'immutable'
UPDATE CustomerReferences SET customer_counter=100, description='invalidate due to X123' WHERE id=2 and description 'immutable'
Problem: I am using the EXPLAIN
and I can't find a way to make the query filter the rows directly from the index. It always uses the index of the primary key or the unique key (c_ref
). How can I index the table so that these updates filter/update directly via the index? Note that the particular updates should be no-ops as if I do select count(*) based on the where
statement I get 0 rows due to the condition description 'immutable'
Asked by Jim
(123 rep)
Oct 20, 2024, 05:41 PM
Last activity: Oct 21, 2024, 07:02 PM
Last activity: Oct 21, 2024, 07:02 PM