简体   繁体   English

SQL:按列值分区

[英]SQL: Partition by Column Value

I have a MySQL table with 20 million rows. 我有一个拥有2000万行的MySQL表。 Querying this database is taking too much time. 查询此数据库花费了太多时间。 The database is in the format below: 数据库格式如下:

Column    Column   Column   Sector

data      data     data     Retail
data      data     data     Utility
data      data     data     Retail
data      data     data     Insurance
data      data     data     Retail
data      data     data     Agriculture
data      data     data     Agriculture
data      data     data     Retail

I want to be able to partition the database by sector. 我希望能够按扇区对数据库进行分区。 This should boost speed for queries where the sector is specified. 这应该提高指定扇区的查询的速度。 I have tried the following and it does not work. 我尝试过以下内容并不起作用。 Where am I going wrong? 我哪里错了?

Alter table 'technical' partition by values in `sector`

https://dev.mysql.com/doc/refman/5.7/en/partitioning-types.html https://dev.mysql.com/doc/refman/5.7/en/partitioning-types.html

From those Partitioning Types, I think LIST COLUMNS partitioning would be the best choice for you. 从那些分区类型,我认为LIST COLUMNS分区将是您的最佳选择。 Read further details about it from here .. 从这里阅读有关它的更多详细信息..

https://dev.mysql.com/doc/refman/5.7/en/partitioning-columns-list.html https://dev.mysql.com/doc/refman/5.7/en/partitioning-columns-list.html

Your code should look like .. 你的代码应该是......

ALTER TABLE technical
PARTITION BY LIST COLUMNS (sector)
  (
    PARTITION p01 VALUES IN ('Retail'),
    PARTITION p02 VALUES IN ('Utility'),
    PARTITION p03 VALUES IN ('Insurance'),
    PARTITION p04 VALUES IN ('Agriculture')
  );

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

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