It probably checks the information_schema database which has all of that information.

--
Kili.io - OpenStack for Africa: kili.io
Musings: twitter.com/varud
About Adam: www.linkedin.com/in/adamcnelson


On Wed, Oct 23, 2013 at 12:38 PM, Peter Karunyu <pkarunyu@gmail.com> wrote:
Dear MySQL gurus, 

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?


_______________________________________________
skunkworks mailing list
skunkworks@lists.my.co.ke
------------
List info, subscribe/unsubscribe
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
------------

Skunkworks Rules
http://my.co.ke/phpbb/viewtopic.php?f=24&t=94
------------
Other services @ http://my.co.ke