complexity theory - Is an SQL query using OR equivalent in running time to multiple SQL queries using UNION? -


it true in mathematics, logical , and or analogous set-theoretic intersect , union. is, if , b sets, {x: x in or x in b} = union b (similarly , and intersect).

my question follows: mathematical equality correspond running-time equivalency in sql? single sql query set of or expressions take time equivalent set of sql queries unioned each other? more precisely, this:

select * a.x = or a.x = b or ... or a.x = z 

equivalent in running time this?

select * a.x = union ... union select * a.x = z 

if implementation matters, i'm concerned mysql (it's use @ work) , postgresql (it's use , @ university).

i expect union slower in theory. consider dataset so:

firstname  age ---------  ---- john       20 matt       30 jess       30 nate       20  tor        10 matt       20  // different matt 

the query select firstname table age in (10,20,30) can go row row , pluck data matches search criteria.

the query select firstname .. union .. select firstname .. union .. have go top bottom (assuming table scan happening) 3 times - once 10, 20 , 30. after getting data, union remove duplicate information. in test case above, matt appears twice. different matts union merge duplicate matts , report 1 (assuming select firstname table ... done).

as commentators mentioned, database may implement or attempt rewrite query differently optimal performance.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -