# MERGE STORAGE ENGINE Vs UNION ALL

**URL:** <https://forums.percona.com/t/merge-storage-engine-vs-union-all/755>\
**Category:** Other MySQL® Questions\
**Created:** [May 13, 2008, 6:17am UTC](https://forums.percona.com/t/merge-storage-engine-vs-union-all/755 "2008-05-13T06:17:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbnewbie](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dbnewbie](https://forums.percona.com/u/dbnewbie)\
**Post date:** [May 13, 2008, 6:17am UTC](https://forums.percona.com/t/merge-storage-engine-vs-union-all/755/1 "2008-05-13T06:17:16Z")

</div>

Hi,

Can anyone tell me if and how, a MERGE STORAGE ENGINE results in a better performance or a faster query than using a UNION ALL?

Let me explain my requirement in detail. I have the following tables:

TABLE PDATA( ID INT NOT NULL PRIMARY KEY,  
NAME VARCHAR(100) NOT NULL,  
VARIABLE VARCHAR(100) NOT NULL,  
AGENT VARCHAR(100) NOT NULL)

TABLE STATS\_TODAY( ID INT NOT NULL,  
INSTANCE VARCHAR(100) NOT NULL,  
VAL INT NOT NULL)

TABLE STATS\_YESTERDAY( ID INT NOT NULL,  
INSTANCE VARCHAR(100) NOT NULL,  
VAL INT NOT NULL)

Now my query is currently like this :

SELECT NAME,VARIABLE,AGENT,INSTANCE,SUM(VAL) FROM  
(  
SELECT NAME,VARIABLE,AGENT,INSTANCE,VAL FROM STATS\_TODAY,PDATA where STATS\_TODAY.ID=PDATA.ID and (NAME = ‘a’ or NAME=‘b’) and (AGENT=‘c’ or AGENT='d) and (INSTANCE=‘1/1’)

UNION ALL

SELECT NAME,VARIABLE,AGENT,INSTANCE,VAL FROM STATS\_YESTERDAY,PDATA where STATS\_YESTERDAY.ID=PDATA.ID and (NAME = ‘a’ or NAME=‘b’) and (AGENT=‘c’ or AGENT='d) and (INSTANCE=‘1/1’)

) group by ID,INSTANCE order by NAME,AGENT limit 1,10.

PS: STATS\_YESTERDAY,STATS\_TODAY are just 2 of the many tables which could be used in UNION ALL query.

Given the above scenario, i want to know if a MERGE would be a better option than UNION ALL.

Thanks !
