I have such a talbe:
CREATE TABLE UserTrans (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`transaction_id` varchar(255) NOT NULL default '0',
`source` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
)
with innodb engine.
Transaction transaction_id is var, because sometimes it can be aphanumeric.
An identifier is a primary key.
so .. that’s what, I have more than 1 M records. However, there is a request to check the duplicate transaciton_id for the specified source. So here is my query:
SELECT *
FROM UserTrans
WHERE transaction_id = '212398043'
AND source = 'COMPANY_A';
this request becomes very slow, for example, 2 seconds to run. Should I index transaction_id and source?
e.g. KEY join_id( transaction_id, source)
What is the disadvantage if I do this?
source
share