# Partitioned view performance

**URL:** <https://forums.percona.com/t/partitioned-view-performance/739>\
**Category:** Other MySQL® Questions\
**Created:** [April 29, 2008, 11:39pm UTC](https://forums.percona.com/t/partitioned-view-performance/739 "2008-04-29T23:39:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saleyoun](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saleyoun](https://forums.percona.com/u/saleyoun)\
**Post date:** [April 29, 2008, 11:39pm UTC](https://forums.percona.com/t/partitioned-view-performance/739/1 "2008-04-29T23:39:16Z")

</div>

How come MySQL is not using the indexes when querying the view? Each one of these tables have about 600,000,000 records.  
Here are the tables definition

CREATE TABLE tbl2005 (  
Col1 datetime,  
Col2 varchar(12),  
Col3 char(2));  
CREATE INDEX idx\_tbl2005\_Col1\_Col2 ON tbl2005 (Col1, Col2);

CREATE TABLE tbl2006 (  
Col1 datetime,  
Col2 varchar(12),  
Col3 char(2));  
CREATE INDEX idx\_tbl2006\_Col1\_Col2 ON tbl2006 (Col1, Col2);

CREATE VIEW vwMyView  
AS  
SELECT Col1,  
Col2  
FROM tbl2005  
UNION  
SELECT Col1,  
Col2  
FROM tbl2006;

SELECT \*  
FROM vmMyView  
WHERE Col1 = ‘20050110’;

This SELECT statement will take forever.

But if I run from the query window the DML specified in the view with the WHERE clause, I get the results inmediately - see below.  
SELECT Col1,  
Col2  
FROM tbl2005  
WHERE Col1 = ‘20050110’  
UNION  
SELECT Col1,  
Col2  
FROM tbl2006  
WHERE Col1 = ‘20050110’;

---

<div class="post-metadata">

**Author:** ![debug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/debug/32/772_2.png) [@debug](https://forums.percona.com/u/debug)\
**Post date:** [May 3, 2008, 11:37pm UTC](https://forums.percona.com/t/partitioned-view-performance/739/2 "2008-05-03T23:37:01Z")

</div>

Can you please show EXPLAIN for both query using view and direct query?
