perf(analytics): 5表 updated_at 窄索引——health MAX 消除全表扫(128MB buffer pool)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-04 16:40:01 +08:00
parent 5b6a9bd35b
commit af05e58976
3 changed files with 105 additions and 0 deletions
+13
View File
@@ -256,6 +256,9 @@ class Customer(Base):
"owner_account_id",
"friend_id",
),
# /api/analytics/health MAX(updated_at) 新鲜度探针;无索引时全表扫。
# 「模型+迁移双声明」防 alembic autogenerate 反 DROP(c3d4e5f6a7b8)。
Index("ix_customer_updated_at", "updated_at"),
)
@@ -314,6 +317,8 @@ class ChatGroup(Base):
"owner_account_id",
"room_id",
),
# /api/analytics/health MAX(updated_at) 新鲜度探针(c3d4e5f6a7b8)。
Index("ix_chat_group_updated_at", "updated_at"),
)
@@ -480,6 +485,9 @@ class Media(Base):
__table_args__ = (
Index("ix_media_type_channel", "media_type", "channel"),
# /api/analytics/health MAX(updated_at) 新鲜度探针——media 5 万宽行
# (多个 TEXT/JSON 列)在 128MB buffer pool 下最伤(c3d4e5f6a7b8)。
Index("ix_media_updated_at", "updated_at"),
)
@@ -531,6 +539,8 @@ class PhoneCall(Base):
__table_args__ = (
Index("ix_phone_call_user_time", "user_id", "start_call_time"),
# /api/analytics/health MAX(updated_at) 新鲜度探针(c3d4e5f6a7b8)。
Index("ix_phone_call_updated_at", "updated_at"),
)
@@ -649,6 +659,9 @@ class MomentsPost(Base):
fetched_at: Mapped[dt.datetime] = _fetched_at()
updated_at: Mapped[dt.datetime] = _updated_at()
# /api/analytics/health MAX(updated_at) 新鲜度探针(c3d4e5f6a7b8)。
__table_args__ = (Index("ix_moments_post_updated_at", "updated_at"),)
# ===========================================================================
# 5. Operational / bookkeeping tables (local; no raw_json/version)