我是 MySQL 的新手,我嘗試使用 MySQL 來存盤我的股票資料。
我boe100在參考中遵循了答案:
- 用于組織歷史股票資料的資料庫模式
我創建我的表如下:
mysql> 描述 StockDailyQuotations;
| 場地 | 型別 | 空值 | 鑰匙 | 默認 | 額外的 |
|---|---|---|---|---|---|
| ts_code | 變數字符(9) | 不 | PRI | 空值 | |
| 交易日期 | 整數(8) | 不 | PRI | 空值 | |
| 打開 | 十進制(6,2) | 不 | 空值 | ||
| 高的 | 十進制(6,2) | 不 | 空值 | ||
| 低的 | 十進制(6,2) | 不 | 空值 | ||
| 關閉 | 十進制(6,2) | 不 | 空值 | ||
| 改變 | 十進制(6,2) | 是的 | 空值 | ||
| pct_chg | 漂浮 | 是的 | 空值 | ||
| 卷 | 漂浮 | 是的 | 空值 | ||
| 數量 | 漂浮 | 是的 | 空值 |
10 rows in set (0.00 sec)
我總是通過以下兩種方式使用該表:
(1) 查詢一只股票的歷史資料,耗時0.01秒。
SELECT * FROM StockDailyQuotations WHERE ts_code='000001.SZ';
(2) 一天內搜索所有股票的資料。需要 1.94 秒。
SELECT * FROM StockDailyQuotations WHERE trade_date='20201231';
The answer in reference said: "We also have a clustered index on symbol, date and time columns. We can get data out of the server in a matter of milliseconds. Remember, the database size is almost 1 terabyte." But in my case, searching 1 is fast enough, I want to accelerate type 2 searching.
I think the primary key on ts_code and trade_date is already made the clustered index. Do I misunderstand anything? How can I accelerate the searching (2)?
I apologize if it is a stupid problem. Thanks for your time.
uj5u.com熱心網友回復:
我為“trade_date”創建了一個索引,搜索方式(2)可以與方式(1)具有相同的性能。
uj5u.com熱心網友回復:
(這不是一個“愚蠢的問題”,只是一個“新手問題”。)
PRIMARY KEY(ts_code, trade_date)
INDEX(trade_date)
但是有trade_date DATE(沒有INT)
DECIMAL(6,2)將您限制為 9999.99;這可以嗎?
用 ENGINE=InnoDB
其他未標記[mysql]或[mariadb]的問題要謹慎;他們可能有對 MySQL 不利的語法和其他建議。
如果包括“時間”,最好使用單列DATETIME,而不是兩列(DATE和TIME)。但是,這在請求給定日期的資訊時會導致一些棘手的業務。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/342407.html
上一篇:MySQL觸發器中的IF陳述句
