tags:

views:

32

answers:

2

Is there a Mysql statement which provides full details of any other open connection or user? Or, an equally detailed status report on myisam tables specifically. Looking at Mysql's SHOW TABLE STATUS documentation, it's missing some very important information for my purpose.

What I'm trying to do: remote odbc connection one is inserting several thousand records, which due to a slow connection speed can take up to an hour. Tcp connection two, using PHP on the server's localhost, is running select queries with aggregate functions on that data. Before allowing connection two to run those queries, I'd like connection two to first check to make sure there's no pending inserts on any other connection on those specific tables so it can instead wait until all data is available. If the table is currently being written to, I'd like to spit back to the user of connection two an approximation of how much longer to wait based on the number of pending inserts. Ideally by table, I'd like to get back using a query the timestamp when connection one began the write, total inserts left to be done, and total inserts already completed. Instead of insert counts, even knowing number of bytes written and left to write would work just fine here.

Obviously since connection two is a tcp connection via a PHP script, all I can really use in that script is some sort of query. I suppose if I have to, since it is on localhost, I can exec() it if the only way is by a mysql command line option that outputs this info, but I'd rather not. I suppose I could simply update a custom-made transaction log before and after this massive insert task which the PHP script can check, but hopefully there's already a built-in Mysql feature I can take advantage of.

Edit: "Transaction" was the wrong word - a language collision. I'm not actually using Mysql transactions. What I meant was currently pending tasks, queries, and requests.

+1  A: 

You can issue SHOW FULL PROCESSLIST; to show the active connections.

As for the rest, mysql doesn't know how many inserts are left, and how long they'll take. (And if you're using MyISAM tables, they dont support transactions). The server have no way of knowing whether your PHP scripts intend to send 10 more inserts, or 10000 - and if you're doing something like insert into xxx select ... from ... - mysql doesn't track/expose info on how much/many is done/is left .

You're better off handling this yourself via other tables where you update/insert data about when you started aggregating data, track the state,when it finished etc.

nos
I'm getting inconsistent results on `SHOW FULL PROCESSLIST`. While in the middle of that long multi-insert task on another connection, the process list shows no such activity except only once out of a dozen requeries. As me running that show, I'm the only one not "asleep". Checking the Info column, I'm the only one with a value there, which obviously just shows "SHOW FULL PROCESSLIST". But that 12th time showed the actual insert process for one record, including the sql. But I'm guessing Time column refers to the execution of that one insert before disappearing. So close to what I need!
bob-the-destroyer
Oh, and I am using insert into xxx select ... from ..., but the Info column on that insert task process showed only a single, regular insert of a selected record. But I could tell records were being added the whole time as the PHP script continually shows an increasing number of records. Guessing timing issue.
bob-the-destroyer
Yes it's a timing issue, the server shows what's happening at the exact time you issue "show full processlist". If you check the status inbetween 2 inserts, you won't see it, as the mysql server cannot guess that the client have another insert it wants to perform.
nos
This looks like the best answer in this case: a custom state-tracking table.
bob-the-destroyer
A: 

If the transactions are being performed on InnoDB tables, you can get full transaction details with SHOW INNODB STATUS. It's a huge blob of output, but part of it is transactions/lock status for each process/connection.

Marc B