feat: 工参表按 CGI 和基站 ID 加索引
CellData_4G 唯一索引改为 (cgi, snapshot_id),另加 (enodeb_id, snapshot_id);CellData_5G 对应 (ncgi, snapshot_id)、(gnodeb_id, snapshot_id),跨日期按小区或基站查询都能走索引。
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""按小区标识和基站 ID 跨快照查询:唯一索引改成小区标识在前,另加基站 ID 索引。"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "0009_celldata_lookup_index"
|
||||
down_revision = "0008_celldata_split"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
TABLES = (
|
||||
("CellData_4G", "celldata_4g", "cgi", "enodeb_id", "enodeb"),
|
||||
("CellData_5G", "celldata_5g", "ncgi", "gnodeb_id", "gnodeb"),
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
for table, prefix, key, node, node_label in TABLES:
|
||||
with op.batch_alter_table(table) as batch:
|
||||
batch.drop_constraint(f"uq_{prefix}_{key}", type_="unique")
|
||||
batch.create_unique_constraint(f"uq_{prefix}_{key}", [key, "snapshot_id"])
|
||||
batch.create_index(f"ix_{prefix}_{node_label}", [node, "snapshot_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
for table, prefix, key, node, node_label in TABLES:
|
||||
with op.batch_alter_table(table) as batch:
|
||||
batch.drop_index(f"ix_{prefix}_{node_label}")
|
||||
batch.drop_constraint(f"uq_{prefix}_{key}", type_="unique")
|
||||
batch.create_unique_constraint(f"uq_{prefix}_{key}", ["snapshot_id", key])
|
||||
@@ -106,7 +106,8 @@ class CellData4G(Base):
|
||||
|
||||
__tablename__ = "CellData_4G"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("snapshot_id", "cgi", name="uq_celldata_4g_cgi"),
|
||||
UniqueConstraint("cgi", "snapshot_id", name="uq_celldata_4g_cgi"),
|
||||
Index("ix_celldata_4g_enodeb", "enodeb_id", "snapshot_id"),
|
||||
Index("ix_celldata_4g_station", "snapshot_id", "station_name"),
|
||||
)
|
||||
|
||||
@@ -134,7 +135,8 @@ class CellData5G(Base):
|
||||
|
||||
__tablename__ = "CellData_5G"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("snapshot_id", "ncgi", name="uq_celldata_5g_ncgi"),
|
||||
UniqueConstraint("ncgi", "snapshot_id", name="uq_celldata_5g_ncgi"),
|
||||
Index("ix_celldata_5g_gnodeb", "gnodeb_id", "snapshot_id"),
|
||||
Index("ix_celldata_5g_station", "snapshot_id", "station_name"),
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
| --- | --- |
|
||||
| OpenCode 接口、提示词、导出核对 | `backend/app/nqi/opencode.py` |
|
||||
| 快照合并、入库、日期规则、邻站 | `backend/app/collect/gongcan.py` |
|
||||
| 表结构 | `backend/app/models.py` 的 `GongcanSnapshot`、`CellData4G`、`CellData5G`,迁移 `0007_gongcan_snapshot`、`0008_celldata_split` |
|
||||
| 表结构 | `backend/app/models.py` 的 `GongcanSnapshot`、`CellData4G`、`CellData5G`,迁移 `0007`–`0009` |
|
||||
|
||||
## 一份快照怎么来
|
||||
|
||||
@@ -50,8 +50,13 @@
|
||||
- `loading` 超过 40 分钟没更新视为取数进程已死,下一个任务接手。
|
||||
- `failed` 冷却 10 分钟,期间别的任务直接报“刚取失败”,不反复打平台。
|
||||
- 邻站直接用库里全市快照算,不再按方框扩大范围多次导出。
|
||||
- 索引:两张小区表各有唯一(快照,`cgi`/`ncgi`)和(快照,`station_name`),地市和日期走 `gongcan_snapshot` 的唯一索引。
|
||||
判断目标在不在某天快照里,按 CGI 和按站点名都只走索引。
|
||||
- 索引(地市和日期走 `gongcan_snapshot` 的唯一索引):
|
||||
|
||||
| | `CellData_4G` | `CellData_5G` | 用途 |
|
||||
| --- | --- | --- | --- |
|
||||
| 唯一 | (`cgi`, 快照) | (`ncgi`, 快照) | 按小区查,跨所有日期或指定日期 |
|
||||
| 普通 | (`enodeb_id`, 快照) | (`gnodeb_id`, 快照) | 按基站查,跨所有日期或指定日期 |
|
||||
| 普通 | (快照, `station_name`) | (快照, `station_name`) | 读整份快照、按站点名查、级联删除 |
|
||||
- 快照默认全部保留,系统不自动删除。要删时手动删 `gongcan_snapshot` 的行,两张小区表按外键级联删除;
|
||||
不要删 `status = 'loading'` 的行,那是正在取数的快照。
|
||||
- 实测江门两份快照(约 12.3 万个小区)占 52 MB,其中索引 13 MB,即每份约 26 MB。
|
||||
|
||||
Reference in New Issue
Block a user