开发者

Partitioning and subselects

开发者 https://www.devze.com 2023-02-21 12:22 出处:网络
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 ha

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号