简体   繁体   中英

Indexing a table partition in MySql

In my project I have a table with around 20 columns. We have partitioned table on column 'status'. For the sake of simplicity let's say there are two possible values of status "ERROR" and "SUCCESS". Hence we have two partitions say p1 and p2 for the table. What we want is to have different indexes on each of the partitions. For example, partition p1 needs to have index on column1 and column2 whereas partition p2 needs to have index on column 4 and column 5.

Is it possible to apply index on individual partition of table in MySql instead of applying indexes at table level? I am using Mysql 5.5. The reason I don't want to apply indexes at table level is that it will make all inserts slow. Insert in this table will have impact on response time to user. However updates happen via job, hence response time is not an issue.

In MySQL indexing works at the table level, not the partition level.

From your question it seems like you need to be ready to do a lot of very fast queries that look like

 SELECT something WHERE status='ERROR' and col1='val' and col2='val'

and

 SELECT something WHERE status='SUCCESS' and col4='val' and col5='val'

Will you ever do an UPDATE that changes the value of the status column? If not you could insert your SUCCESS and ERROR items into different tables, each indexed appropriately. If you need to retrieve them together you can use a VIEW to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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