So I have this query:
CREATE TABLE IF NOT EXISTS my_table_a ( SELECT * FROM my_table_b WHERE some_column=some_value);
My question is, how does MySQL evaluate it? Does it start with the SELECT * then goes to check if that table exists, then creates the table?
The reason I am asking is because the SELECT * FROM my_table_b WHERE some_column=some_value part is particularly nasty and takes forever, and therefore, I was thinking of splitting it into two thus:
1. $x = SELECT COUNT(1) FROM information_schema.tables WHERE table_schema='my_db' AND table_name='my_table_a'
2. if ( ! $x ) { CREATE TABLE my_table_a ( SELECT * FROM my_table_b WHERE some_column=some_value); }
And therefore, possibly save a few seconds.
Or am I searching for speed in the wrong place?