I’m currently using AWS Aurora Mysql(ServerlessV2).
Engine version: Aurora MySQL 3.04.0 (compatible with MySQL 8.0.28)
I have table like below:
CREATE TABLE "Test" (
"key1" varchar(37) NOT NULL,
"key2" varchar(50) NOT NULL,
"key3" varchar(20) NOT NULL,
"createdDate" timestamp(3) NOT NULL,
"createdBy" varchar(50) NOT NULL,
"updatedDate" timestamp(3) NOT NULL,
"updatedBy" varchar(50) NOT NULL,
PRIMARY KEY ("key1","key2","key3")
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
I have simple query that
select key3
FROM Test WHERE key1 =
'value1' and key2= 'value2'
It took me arround 30-35 seconds to return 4 milion row(s).
3934328 row(s) returned
Duration/fecth: 0.141 sec / 34.375 sec
About innodb_buffer_pool_size, its about 2Gb
SELECT @@innodb_buffer_pool_size
--
@@innodb_buffer_pool_size
2471493632
I tried to increase innodb_buffer_pool_size to arround 7Gb by increase Serverless v2 capacity settings. But seems no affection. It is still slow.
I want it to be under 5s to get arround 4milions records.
Can you suggest anyway to speed up this query
2
Answers
ggever, In your Parameters group, consider this suggestion,
after this change, logoff/logon for the new NBL to be in service and get new timings, please. Please post Duration information so we all know what this one change does for you.
and check it again in a week to be sure your settings are still in service.
If not let AWS know what you are trying to accomplish, please.
View profile, please.
The problem is not in the speed of the query – that lasts about 140 milliseconds. Your problem is in getting the results, i.e. four million values of key3.
For some reason, those (at most) 240 megabytes take 34 seconds to be transferred.
You already have keys 1-3 in a primary key, so indexing will yield no gains.
The best approach would be to reduce the number of values returned:
key3, count(*) ... GROUP BY key3
? Or might aDISTINCT
be enough?Otherwise, other things might help:
OPTIMIZE TABLE
on your Test?utf8mb4
collation? For simple textual values,ascii_bin
sometimes yields better performances.