I have a very simple table with 100,000 rows.
CREATE TABLE test_database.products (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`city_id` int NOT NULL,
`market_id` int NOT NULL,
`product_id` int NOT NULL,
`search` varchar(450) COLLATE utf8mb4_unicode_ci NOT NULL,
`quantity` int NOT NULL,
`price` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_general_ci;
I added fulltext:
ALTER TABLE products ADD fulltext (search);
And when I search:
SELECT
id, market_id, product_id, quantity, price,
MATCH(pr.search) AGAINST('dolor* qui*' IN BOOLEAN MODE) as srv
from
products pr
where
pr.city_id = 1 and
MATCH(pr.search) AGAINST('dolor* qui*' IN BOOLEAN MODE)
ORDER by
srv DESC;
It takes ~ 2500 ms.
Explain select ...
id|select_type|table|partitions|type |possible_keys|key |key_len|ref |rows|filtered|Extra |
--|-----------|-----|----------|--------|-------------|------|-------|-----|----|--------|-----------------------------|
1|SIMPLE |pr | |fulltext|search |search|0 |const| 1| 10.0|Using where; Ft_hints: sorted|
MySQL version:
Ver 8.0.21 for Win64 on x86_64
What I'm doing wrong?