I have a PDO connection to a MySQL database. Making the connection is lightening fast. Subsequently I run a very complicated query 1 (using temp tables, SELECT, INSERT and other operations all subsequently) which runs extremely fast (around 0.1 second). I know this query 1 is successfully executed every time.
Much further in the code I am opening a new PDO connection to do a simple SELECT statement. This SELECT statement seemed not to be fetching any results (it will only fetch results if the complicated query 1 is successfully finished).
As I opened a connection earlier to execute the complicated query 1 I thought I would have to close that one first. I added the below code to unset the connection. This helped. However, I can see now that it takes a few minutes to run only the piece of code: unset($stmt);
$stmt = $pdo->prepare($QUERY);
$stmt->execute();
unset($stmt);
unset($pdo);
Could it be that my complicated query is running in the background while I think it is finished, but it actually isn't?
My question is: Why does executing this code: unset($stmt); take so extremely long?
The query I was executing simply took too long and was still running on the background while the php parser continued.
Related
I have a database query which deletes from database with some given conditions. The query is being initiated by an endpoint which timeouts if the query takes a long time (which it does). The service which calls this endpoint needs to do some other tasks after this operation is successful. So we need to know when this query completes. The query is :
DELETE FROM foo WHERE creation_time BETWEEN ? AND ? AND bar_id = ?
How do I know when the query completes? I am using jdbctemplate for querying the database.
I thought of one option but now sure how the between query works internally.
I thought of creating a status endpoint which checks if the query is still running? The endpoint will check if there is any row in foo where creation_time = FROM and bar_id = id.
But I don't know how mysql handles the BETWEEN query internally. If it starts deleting from the FROM or the TO or anything in between.
Short question : How do I check if my query is still running or finished with jdbctemplate?
You can execute the SHOW FULL PROCESSLIST; command. See the MySQL docs for a good description of the command.
This will show all running threads, along with the query that is currently executing and the time that it has been running.
Then parse the output to see if your query is still running.
Hope this helps.
The following is the list of process in my database
Is there anyways to solve my database performance problem. Whenever I run mysql query it takes about 1 minute or more than 1.
And find the following image to retrieve some records from the database it takes even longer.
I am working on converting unix time to readable time.
It is necessary to insert a 6gb .txt file into my database
(XAMPP V3.2.2 , MYSQL workbench 5.2.34).
I have written the SQL query to convert unix time but whenever i run the query, Mysql workbench will crash
(error:2013.lost connection to database during query.).why?
my SQL query:UPDATE database.database SET readable_time=from_unixtime(unix_time);
Increasing net_read_timeout solves this problem
From doc:
Sometimes the “during query” form happens when millions of rows are being sent as part of one or more queries. If you know that this is happening, you should try increasing net_read_timeout from its default of 30 seconds to 60 seconds or longer, sufficient for the data transfer to complete.
Click here for more info.
Please check this post - Error Code: 2013. Lost connection to MySQL server during query
As you are talking about an insert, understand that the 'Workbench' loses the connection, but the query continues to execute in the 'server'. That is, the workbench can no longer update you on the status changes for that query execution. But, the execution of the query keeps continuing behind screens.
You might want to run show processlist to see if the insert process is still running or not.
However, while fetching data from the database, you might have to update your timeout settings.
What's the easiest way to find out how long it takes to evaluate a long-running MySQL query (longer than 10 minutes)?
The issue is that:
When I try to run it from MySQL Workbench, I get a timeout error.
When I look at the process list, sometimes the process finishes executing when I'm not looking and I don't know how long the script has taken.
Is there a simple command that will let me tweak a MySQL DB instance to run slower than normal?
I'm working on code that records and replays database interactions. One of the things it does is keep track of how long a given query/command takes to execute, and if it runs substantially slower during the replay, it throws a warning. Of course, If You Don't Test It, It Doesn't Work; I'm trying to come up with an automated test for this feature. Is there something I can do to my test DB that will screw up performance? All I need to do is reliably add 2+ milliseconds to any given query and I'm set.
If you just want to test long queries, do this: SELECT SLEEP(1);
It shouldn't matter what the query is itself if all you want to do is test if your duration detection works.
(I know this breaks the true "replay" aspect, but it should be trivial to add SLEEP(1) during "playback" to some select statements.)
EDIT:
A second idea, which you might like better: Create a lock on a table from another connection. Run the script. Wait a bit. Remove that lock. It won't involve messing with any of your playback queries.
Basic procedure like so:
begin transaction
do your sql stuff
sleep 2ms in perl or sql
commit
the key is the begin/commit part: it'll keep any locks you acquired, making things as slow as you want them.
Other test to consider:
begin transaction in two processes
do your sql stuff in first process
do your sql stuff in second process
do more sql stuff in each process
commit each process