對 rooms.property_id 與 orders.room_id 建立 index
在 orders 新增 room 的 sku id (format: (PROPERTY_NAME)_(ROOM_SKU), Ex: PROABC_ROOMB), 並對其建立 index。 直接針對 sku 中的 property_name 進行 GROUP BY (Ex: GROUP BY left(orders.room_sku,6))
沒有用上正確的 index 導致 full table scan, 使用 EXPLAIN ANALYSE 去檢查分析出的結果,根據結果最佳化查詢成本
資料量大 (>10M),針對資料存取頻率分級儲存(依照不同年份分開 or 一年以上資料單獨儲存),以確保查詢資料的範圍在限定的時間區間
如果由您來規劃線上通訊服務,您會怎麼設計?請提供您的設計文件,並敘述您的設計目標。
# 線上通訊服務
## Feature
1. Able to send and receive messages between two users. Support formats:
- Text
- Image
2. Receipts for sent, delivered and read status
## Specification
1. Large traffic: 1M messages/day
2. Read/Write ratio: 50/50
3. Large storage: store message at least for 1 year
4. Easy to scale and low cost to maintenance: Cassandra
## Data
```sql
CREATE TABLE messages (
message_id bigint,
room_id bigint,
user_id bigint,
receipt_status int,
content text,
PRIMARY KEY (room_id, message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);
CREATE TABLE rooms (
room_id bigint,
users list<text>,
content text,
PRIMARY KEY (room_id)
);
```
## Overview
https://imgur.com/a/QZJqf2V