简体   繁体   English

Ruby on Rails / ActiveRecord 和表分区

[英]Ruby on Rails / ActiveRecord and Table Partitions

I've read the documentation and been able to find anything to assist me so far.到目前为止,我已经阅读了文档并且能够找到任何可以帮助我的东西。 I've also read a large number of blog articles, but nothing seems to answer my question directly:我也阅读了大量的博客文章,但似乎没有什么能直接回答我的问题:

Is it possible to manage table partitions in an InnoDB table with ActiveRecord?是否可以使用 ActiveRecord 管理 InnoDB 表中的表分区? I'd really prefer to keep things very clean and I'm trying to avoid writing external scripts to try to automate the creation/deletion of partitions over time.我真的更喜欢保持非常干净,并且我试图避免编写外部脚本来尝试随着时间的推移自动创建/删除分区。

Yes, you can!是的你可以! But I don't think that there is a gem that will do it for you.但我不认为有一颗宝石可以为你做这件事。

In order to perform partition management you need to do the hard work by yourself and send the command that you need to run on the DB directly via the connection in the following way为了执行分区管理,您需要自己做艰苦的工作,并通过以下方式直接通过连接发送您需要在数据库上运行的命令

ActiveRecord::Base.connection.execute("ALTER TABLE your_table drop partition p0")

An additional solution has emerged since I first asked this question.自从我第一次提出这个问题以来,出现了一个额外的解决方案。 While the solution does require the use of Postgresql over MySQL or Maria, this isn't a high hurdle since it is more or less the default database for Rails.虽然该解决方案确实需要在 MySQL 或 Maria 上使用 Postgresql,但这并不是一个高障碍,因为它或多或少是 Rails 的默认数据库。

The Partitioned gem on Github specifically handles all of the partitioning mechanics in a nice, Railsy way. Github 上的Partitioned gem 以一种很好的 Railsy 方式专门处理所有的分区机制。

I can't see how ActiveRecord could do things like DROP PARTITION and REORGANIZE PARTITION .我看不出 ActiveRecord 怎么能做DROP PARTITIONREORGANIZE PARTITION之类的事情。 Can it even call a Stored procedure?它甚至可以调用存储过程吗? If so, then build one similar to what is in my blog and call it from Rails.如果是这样,那么构建一个类似于我的博客中的内容并从 Rails 调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM