Partitioning and subselects
I have a problem with the partitioning and subqueries (mysql 5.1). Exactly when I'm executing select with subselect mysql skips partitioning. And I don't understand why. Exactl开发者_如何学Goy, I have one partitioned table like this:
CREATE TABLE parted_table (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(20)
) PARTITION BY KEY() PARTITIONS 20;
Query looks like:
select * from parted_table where id in (select col_fk from other_table);
And explain partitions
shows that above select uses all 20 partitions, even if this subselect returns only one value. Is it caused that mysql doesn't know result set of subselect during optimalization of the query?
What should I do to get partitioning in given example?
Edit: I found a bug considering exactly this issue (http://bugs.mysql.com/bug.php?id=22765). It was fixed in 2008, but it was fixed in mysql 6.0 :( I read that a lot of enchantments were moved from mysql 6.0 to mysql 5.5. At the moment I'm trying to confirm that this particular fix was inclued in ver. 5.5.
If your subquery returns only one row, you can use a regular join. The query would be driven from other_table
into parted_table
.
select *
from other_table
join parted_table on(parted_table.id = other_table.col_fk);
精彩评论