简体   繁体   中英

Performance measure Mysql View VS UNION of table

I try to make a database scheme. I just eager to know which methodology is better than other. I have 2 ways to accomplish a searching task from my database. The condition as follows: I have multiple table name as table1,table2..tablen with same structure which denote diffrent location.

My working way as follows:

  1. Making a VIEW using UNION of my TABLES and use query like: Select * from my_view where my_condition; ".
  2. By using simple UNION operator and use query like:

    select * from table1 where my_condition UNION select * from table2 where my_condition UNION ... .. select * from tablen where my_condition

So my problem is that I want a faster solution sol please help me to choose between VIEW and UNION.If you have any other solution like mysql cluster SCALABLITY tell me.

View is just a saved Named SELECT statement . when you call a view it just simply executes the SELECT statement in its definition there is no such performance benefits from view, but there are some security and code simplicity benefits. Unless you create Indexed View which can improve performance of your view as well as other queries which can benefit from the indexes created on your views. Warning Indexed views come with a long list of limitations.
Union Operator vertically combines result sets from two or more select queries. If you want better performance you need to look at the indexes available on your table for your query.
Carefully inspecting you query's Exection plan will be the best place to start in your case as it will give you some idea what steps SQL SERVER has to go through in order to get the required result set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM