AFAICT when you send a query to MySQL from any client it always blocks and waits for the server to respond with success or failure.
When performing a slow operation like adding a new index on large table this can be a problem as it ties up the client in an idle state waiting a long time for response.
In my case specifically I want to send the request from AWS Lambda function.
I found some tips here https://stackoverflow.com/a/41371255/202168 about how to detach and put the mysql
client process in the background, and also some suggestion that MySQL server is likely to cancel the request if client closes the connection. But the host where the mysql
client was launched still has to stay running.
It feels like this can't be all there is?
PostgreSQL has CREATE INDEX CONCURRENTLY
for this purpose, i.e. the query returns quickly and index building continues on the server.
I am aware that MySQL does not support CREATE INDEX CONCURRENTLY
But it feels weird that there is no non-blocking client method? (well... there are "async" or "non-blocking" clients but they still have to keep the same connection open)
What I want to do is something like:
- send an
ALTER TABLE ... ADD KEY
query - get the server-side process id for the query
- log off the mysql client (and end my Lambda execution)
- the
ADD KEY
keeps running on the server - from a new process, periodically poll the process id of my DDL query and see whether it finished or failed yet
Is there any way to achieve this?
Related or alternative question: if I just disconnect the client after sending query, will the ADD KEY
keep running to completion/failure rather than being cancelled?
Server is MySQL 8.0.35 on AWS RDS, InnoDB tables.