Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I've an MySQL 5.1 slave for our BI team.

They need to make some CREATE SELECT with big select queries (several million lines).

As CREATE SELECT is a DDL, if the replication attempts to update some rows in same tables than the SELECT statement, replication is blocked until the freeing of the CREATE SELECT.

Do you now a good non-blocking alternative to thoses CREATE SELECT statements?

I thought to an SELECT INTO OUTPUT FILE then LOAD DATA INFILE but they will fill out our disks as BI guys like to do... :)

Max.

share|improve this question
Is the CREATE SELECT from a single table or a complex join ? Please post the query you have. – RolandoMySQLDBA Mar 1 at 16:24
Complex joins (8-10 tables it's not a particular query) – mfouilleul Mar 1 at 16:36
Are all the tables InnoDB (please say yes) ??? – RolandoMySQLDBA Mar 1 at 16:37
I think so (pretty sure), i don't have a sample query, we have some MyISAM tables but i think the problem came from the CREATE statement that create a transaction and blocks rows until it'is done. – mfouilleul Mar 1 at 16:46

1 Answer

If you have to perform DDL, do it just to create the table.

For example, suppose you have the following query involving two InnoDB tables:

CREATE TABLE hiringdata
SELECT a.id,a.name,b.hiredate,b.salary
FROM employee a INNER JOIN hrinfo b
ON A.id = B.empid;

Of course, you should expect some pause to

  1. create the table
  2. execute the query
  3. load results info

How you ever considered separating step 1 from the other two steps? All it takes is a simple WHERE clause and an INSERT INTO query:

CREATE TABLE hiringdata
SELECT a.id,a.name,b.hiredate,b.salary
FROM employee a INNER JOIN hrinfo b
ON A.id = B.empid
WHERE 1 = 2;
INSERT INTO hiringdata
SELECT a.id,a.name,b.hiredate,b.salary
FROM employee a INNER JOIN hrinfo b
ON A.id = B.empid;

There you have it: DDL is detached from the SELECT query. This way, any transactions that caches data changes in the Transaction Logs are not held hostage by the CREATE TABLE.

Give it a Try !!!

share|improve this answer
Yes but, it'll by the INSERT statement, it's an DML, so i'll have the same issue – mfouilleul Mar 1 at 17:10
If all tables involved are InnoDB, this should not be a problem. If even one table is MyISAM, expect locking issues indeed (See my StackOverflow post on Mixing InnoDB and MyISAM stackoverflow.com/a/5476284/491757 ) – RolandoMySQLDBA Mar 1 at 17:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.