Mysql

推薦結構?%70 寫入 %30 讀取。10M 行。200 次查詢/秒。選擇、更新、插入、搜尋

  • January 31, 2013

以下是我需要對我的項目做的事情:

1-如果搜尋詞是新的且唯一的,則添加搜尋詞

2- 顯示最近搜尋的 1000 個搜尋詞(我不需要儲存所有搜尋詞的日期)

3- 為一個搜尋詞顯示 20 個相似的搜尋詞

4-如果再次搜尋到舊的搜尋詞,則更新搜尋詞的查看次數。

http://www.ptf.com/tai/tai+ve+dot+kich/和其他一些大網站使用搜尋詞的第一個詞來提高我相信的性能。但我不確定如何應用該結構。

此外,您可以從連結中了解我在做什麼。

這是目前的結構,我知道它很糟糕:

mysql> use article; SHOW TABLE STATUS LIKE 'searches';
Database changed
+----------+--------+---------+------------+--------+----------------+-------------+-----------------+--------------+-----------+----------------+--------------
-------+---------------------+---------------------+-----------------+----------+----------------+---------+
| Name     | Engine | Version | Row_format | Rows   | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time| Update_time         | Check_time          | Collation       | Checksum | Create_options | Comment |
+----------+--------+---------+------------+--------+----------------+-------------+-----------------+--------------+-----------+----------------+--------------
-------+---------------------+---------------------+-----------------+----------+----------------+---------+
| searches | MyISAM |      10 | Dynamic    | 973577 |             40 |    38960308 | 281474976710655 |     91711488 |         0 |           NULL | 2012-02-08 22:22:33 | 2012-02-09 11:32:31 | 2012-02-08 22:23:50 | utf8_general_ci |     NULL |                |         |
+----------+--------+---------+------------+--------+----------------+-------------+-----------------+--------------+-----------+----------------+--------------
-------+---------------------+---------------------+-----------------+----------+----------------+---------+
1 row in set (0.00 sec)

mysql> DESCRIBE searches;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(10)      | NO   |     | NULL    |       |
| q     | varchar(255) | NO   | PRI |         |       |
| date  | datetime     | NO   | MUL | NULL    |       |
| view  | int(10)      | NO   |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
4 rows in set (0.01 sec)


mysql> SHOW INDEXES FROM searches;
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| searches |          0 | PRIMARY  |            1 | q           | A         |      973577 |     NULL | NULL   |      | BTREE      |         |
| searches |          1 | date     |            1 | date        | A         |        3416 |     NULL | NULL   |      | BTREE      |         |
| searches |          1 | q        |            1 | q           | NULL      |       21635 |     NULL | NULL   |      | FULLTEXT   |         |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)

目前,此表有 %70 寫入和 %30 讀取。

假設一秒鐘內有 1000 萬行和 200 次搜尋。對於這種需求,推薦的結構是什麼?

我在這張表上的幾個索引和欄位組合上苦苦掙扎,但我無法做出任何重大改進。因此,如果您能提供幫助,我將很高興!

切換到 InnoDB,然後

  • 將 innodb_buffer_pool_size 設置為至少 250M
  • 向我們展示暫定的 SELECT
  • SHOW CREATE TABLE(DESC 不充分)

對於此類項目……以及寫入多於讀取的場景,並且您需要處理大規模數據,您應該選擇NoSQL,如MongoDBCouchDBHbase等。

引用自:https://dba.stackexchange.com/questions/12525