---
title: "MySQL Index is slowing down the selecting actions"
author: "xxd"
date: "2008-12-25T23:27:34Z"
tags: []
slug: "mysql-index-is-slowing-down-the-selecting-actions"
draft: false
lastmod: "2008-12-25T23:27:34Z"
id: 460604
url: "https://xxd.iteye.com/blog/460604"
---

\*\*Index is slowing down the selecting actions \**

Description the problem:

Table size 30G, Ram size 16G

mysql&gt; select * from program\_access\_log where program\_id between 1 and 4000;

very slow

Try to select the top 500,000 records:

mysql&gt; select * from program\_access\_log where id between 1 and 500000 and program\_id between 1 and 4000;

still very slow

Analysis:

MySQL cann't put this 30G table into Ram, it will read them from disk:

mysql&gt; select * from program\_access\_log where id between 1 and 500000 and program\_id between 1 and 4000;

MySQL will select the program\_id between 1 and 4000 out coz it's smaller then try to find id between 1 and 500000, however the id column didn't store as sorted, so MySQL will read them from disk.

Solutions:

1\. Partition: split program\_id into different partitions

2\. Split tables: split table into smaller tables

3\. select * from program\_access\_log where id between 1 and 500000 and program\_id between 1 and 15000000;

![](https://blogger.googleusercontent.com/tracker/4722768579593920709-66691988360867882?l=xxd79.blogspot.com)