Sample Header Ad - 728x90

clustered index detection with EXPLAIN statement

0 votes
1 answer
24 views
I created two tables with one-to-one relationship as below, CREATE TABLE if not exists User ( id bigint AUTO_INCREMENT, coins bigint not null, level bigint not null, PRIMARY KEY (id) ); CREATE TABLE if not exists Claimingcoins ( userid bigint UNIQUE NOT NULL, claimingCoins bigint ); ALTER TABLE Claimingcoins ADD CONSTRAINT fk_user_id FOREIGN KEY (userid) REFERENCES User (id); Now I run EXPLAIN query on some statements to see if CLUSTERED INDEX is set on both these entities without me having to set it. I use mysql 8.0.28, I suppose it sets it by default. Does it also set it for UNIQUE KEY which is referenced like above? mysql> EXPLAIN UPDATE Claimingcoins SET claimingCoins = 100 where userid IN(2999999); +----+-------------+---------------+------------+-------+---------------+--------+---------+-------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+---------------+------------+-------+---------------+--------+---------+-------+------+----------+-------------+ | 1 | UPDATE | Claimingcoins | NULL | range | userid | userid | 8 | const | 1 | 100.00 | Using where | +----+-------------+---------------+------------+-------+---------------+--------+---------+-------+------+----------+-------------+ 1 row in set, 1 warning (0,00 sec) mysql> EXPLAIN SELECT id,coins,level FROM User WHERE id IN (29999, 299, 299999); +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+ | 1 | SIMPLE | User | NULL | range | PRIMARY | PRIMARY | 8 | NULL | 3 | 100.00 | Using where | +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+ I ran the EXPLAIN statements for the queries and I get the results above. How can I understand by looking at this table if clustered index is set? I see possible_keys and key values are exposed, so I believed those should be the one used for CLUSTERED INDEXES, right?
Asked by umarkaa (47 rep)
Apr 4, 2024, 05:58 AM
Last activity: Apr 4, 2024, 09:08 AM