sql - MySQL Select From Multiple Structurally Identical Tables -


let me preface saying yes aware beginner dba should know answer question, have never had formal training , can't find answer after quite bit of googling, please go easy on me :)

i have database containing 88 identical (in structure, not data) tables total 20465 rows. looking way aggregate these can:

select * [aggregate] id = 'some unique value'; 

the (working slow) solution came create view select * each table , union them together, apparent me when doing search not correct way this. example selecting ~200 records takes on minute.

this not seem use case join tables have no relation 1 another, contain same kind of data.

i feeling index looking for, unsure if should indexing view (my googling seems indicate not possible?) or if maybe not understanding indices properly.

any tips in right direction appreciated! (even if it's link documentation).

the commenter correct. use union all rather union. union all doesn't attempt deduplicate rows, union does. deduplicating lot of work, if there aren't duplicates.

you need use series of union operations treat these tables 1 table. that's how it.

if me i'd run query once:

  create new_table              select 1 source, * table1   union  select 2 source, * table2   union  select 3 source, * table3        etc etc ad nauseam   union  select 88 source, * table88 

then use new_table future work. i'd drop 88 tables after that.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -