Run query on specific partition of partitioned MySQL table
Asked Answered
V

0

6

I would like to run my Ecto.Query.from on a specific partition of a partitioned MySQL table.

Example table:

CREATE TABLE `dogs` (
  `dog_id` bigint(20) unsigned NOT NULL,
   ...
  PRIMARY KEY (`dog_id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY HASH (dog_id)
PARTITIONS 10 */ 

Idealistic query for what I would like to achieve:

from(i in dogs, select: i.dog_id, partition: "p1")

The above doesn't work ofc, so I have achieved this with transforming the query to string with Ecto.Adapters.SQL.to_sql and editing it.

... <> "PARTITION (#{partition}) AS" <> ...

This feels hacky and it might break with future versions, is there a way to achieve this with Ecto?

Venturous answered 25/10, 2018 at 1:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.