I read some explanations about "sending data" status but I still don't get if the query is running or not. They say "sending data" means server sending some data to client but I really don't which data is sending.
What does it mean when MySQL is in the state "Sending data"?
I run some query using Mysql Workbench and while this query is executing Workbench goes timeout(after 10 min). Then I run "show processlist" command to see if query is continues to executing or not. It says my query status is "sending data".
By the way logs table has 10 million records. So this query must be finish in 10 hours. I just want to know if my query is really executing still?
update logs join user
set logs.userid=user.userid
where logs.log_detail LIKE concat("%",user.userID,"%");
When it's in the process list it is still running. Your query is just running very slow, I assume, cause you're doing a cross join (which means you connect every column of one table to every column of the other table, which can result in quite an enormous amount of data, therefore I further assume, that your query does not do, what you think it does) and no index can be used on the where clause. You're probably doing a full table scan on a very huge amount of data. You can verify this by doing an explain <your query>;.
To avoid the cross join specify the connection in an on clause, like
update logs join user ON logs.userid = user.userid
set logs.whatever = user.whatever
where logs.log_detail LIKE concat("%",user.userID,"%");
Related
I have a table with >19M rows that I want to create a subtable of (I'm breaking the table into several smaller tables). So I'm doing a CREATE TABLE new_table (SELECT ... FROM big_table). I run the query in MySQL Workbench.
The query takes a really long time to execute so eventually I get a "Lost connection to MySQL server" message. However, after a few minute the new table is there and it seems to contain all the data that was supposed to be copied over (I'm doing a GROUP BY so cannot just check that the number of rows are equal in both tables).
My question is: Am I guaranteed that the query is completed even though I lose connection to the database? Or could MySQL interrupt the query midway and still leave a table with incomplete data?
Am I guaranteed that the query is completed even though I lose connection to the database?
No. There are several reasons other than connection timeout to get lost-connection errors. The server might crash due to used-up disk space or a hardware fault. An administrator might have terminated your session.
"Guarantee" is a strong word in the world of database management. Because other peoples' data. You should not assume that any query ran correctly to completion unless it ended gracefully.
If you're asking because an overnight query failed and you don't want to repeat it, you can inspect the table with stuff like COUNT(*) to convince yourself it completed. But please don't rely on this kind of hackery in production with other peoples' data.
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.
A program I inherited runs 800 single queries once every minute or so. I was able to grab all these queries and I want to test to see how long it takes to run them in a sequence to see if its an issue that I need to address or if it is ok as is.
The SQL queries are all simple SELECT queries with a few where clauses:
SELECT DISTINCT roles.desc FROM descRoles roles, listUsers users, listUsers mapping WHERE mapping.roleId = roles.roleId AND mapping.idx = users.idx AND users.UserName = 'fakeNameHere';
If there's a typo in my select query please ignore it they run fine. I want to know if there is something I can put before and after all 800 queries to time how long it takes to run all of them. Also, if I could turn off the result tabs on them since after about 40 I get a message that my maximum result tabs are reached, that also seems necessary.
Workbench is not the tool for timing queries. What you want is mysqlslap https://dev.mysql.com/doc/refman/8.0/en/mysqlslap.html
Well here is my question, I messed up yesterday and made a delete query on my database. The messing up is not the delete part, but the fact that i didnt realized it was 424 million records. I keeping track on the query with the information schema but i would like to know what the "updating" state stands by. What is it doing right now, deleting or what?
Here is the get
"COMMAND": Query
"STATE": "updating"
"INFO": "delete from posicion where fechahora between '2012-12-12 00:00:00' and '2014-12-15 00:00:00'"
It looks to me like your delete query is still running.
You can double check this by issuing this command, from some other client besides the one from which you issued the delete query.
SHOW FULL PROCESSLIST
This will show your active processes and what they are doing. Your DELETE query may be among them.
If you
don't want to delete those rows.
are using InnoDB for your posicion table, and
have not yet finished running the DELETE query
you can look at the processlist to get the id of your delete operation, then issue the command
KILL QUERY id
InnoDB should roll back the in-progress delete and leave your table as it was before you started the DELETE .
Good luck!
I realized that using phpMyAdmin for testing the speed of queries might be dumb: it automatically applies a LIMIT clause.
I tried a certain query on a fairly large number of records (31,595) with a GROUP BY clause. phpMyAdmin, adding LIMIT 0, 200, took 0.1556 seconds to fetch the results.
I decided to try the same query from the command line without the LIMIT clause and it took 0.20 seconds. Great, so now I have the real time it takes for that query.
But the downside is I had to wait for 30,000+ records to print on the screen.
Is there a better solution?
EDIT:
To clarify, I am looking for a way to suppress the screen output of a select query while still getting an accurate time for running the query. And I want it to be something that could be typed in and timed at any time (i.e. I don't want to have to tweak slow log settings to capture results).
You could enclose your query in SELECT COUNT(1) to count the number of rows returned, without having all the rows printed out:
SELECT COUNT(1)
FROM (
<<you query goes here>>
) t;
I guess that what you really want is to obtain the best possible speed for your query, not really to time it.
If it's the case, type your query in phpMyAdmin (its adding a LIMIT clause is not important) then click on the "Explain SQL" link to see whether you are using indexes or full-table scans.
You could use console client mysql and time
$ time mysql -u user -h host -ppassword -e "show databases;" > /dev/null
real 0m0.036s
user 0m0.008s
sys 0m0.008s