mysql - 海量数据库和mysql

标签 mysql database-design optimization nosql

我们正在进行的一个新项目需要大量数据分析,但我们发现这非常缓慢,我们正在寻找方法来改变我们使用软件和/或硬件的方法。

我们目前在亚马逊 ec2 实例 (linux) 上运行:

High-CPU Extra Large Instance

7 GB of memory
20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each)
1690 GB of instance storage
64-bit platform
I/O Performance: High
API name: c1.xlarge


processor       : 7
vendor_id       : GenuineIntel
cpu family      : 6
model           : 26
model name      : Intel(R) Xeon(R) CPU           E5506  @ 2.13GHz
stepping        : 5
cpu MHz         : 2133.408
cache size      : 4096 KB

MemTotal:      7347752 kB
MemFree:        728860 kB
Buffers:         40196 kB
Cached:        2833572 kB
SwapCached:          0 kB
Active:        5693656 kB
Inactive:       456904 kB
SwapTotal:           0 kB
SwapFree:            0 kB

数据库的一部分是文章和实体以及链接表,例如:

mysql> DESCRIBE articles_entities;
+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| id         | char(36)     | NO   | PRI | NULL    |       | 
| article_id | char(36)     | NO   | MUL | NULL    |       | 
| entity_id  | char(36)     | NO   | MUL | NULL    |       | 
| created    | datetime     | YES  |     | NULL    |       | 
| modified   | datetime     | YES  |     | NULL    |       | 
| relevance  | decimal(5,4) | YES  | MUL | NULL    |       | 
| analysers  | text         | YES  |     | NULL    |       | 
| anchor     | varchar(255) | NO   |     | NULL    |       | 
+------------+--------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

正如您从下表中看到的,我们有很多协会以每天 100,000+ 的速度增长

mysql> SELECT count(*) FROM articles_entities;
+----------+
| count(*) |
+----------+
|  2829138 | 
+----------+
1 row in set (0.00 sec)

像下面这样的简单查询花费了太多时间(12 秒)

mysql> SELECT count(*) FROM articles_entities WHERE relevance <= .4 AND relevance > 0;
+----------+
| count(*) |
+----------+
|   357190 | 
+----------+
1 row in set (11.95 sec)

为了缩短查找时间,我们应该考虑什么?不同的数据库存储?不同的硬件。

最佳答案

如 mrorigo 所问,请提供 SHOW CREATE TABLE articles_entities 以便我们可以看到您表的实际索引。

作为 MySQL 文档中的注释 http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to find rows. 
For example, if you have a three-column index on (col1, col2, col3), you have indexed search capabilities on (col1), (col1, col2), and (col1, col2, col3).

MySQL cannot use an index if the columns do not form a leftmost prefix of the index

因此,如果 relevance 是多列索引的一部分,但不是该索引的最左边的列,则该索引不会用于您的查询。

这是一个经常被忽视的常见问题。

关于mysql - 海量数据库和mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4746569/

相关文章:

php - 使用PDO提取单行,单列

database-design - 在 2 列上建立索引和在每一列上分别建立索引有什么区别?

ruby-on-rails - rails 3 : Optimize database call

c++ - 不是编译器优化 C++ 中的代码部分

sql - 在子查询中使用 DISTINCT 时如何重写子查询以使用连接?

mysql - 应该删除已索引的 SQL 表中的状态列

php - MYSQL转PDF为空白

database-design - 亚马逊发电机数据库模型

sql - 模式 : two-way relationships? 哪个表/实体应该拥有 'preference'?

c# - 有哪些方法可以动态获取 DateTime.Now.AddDays(0..7) 的列表?