20261008-ide1.0发布 #1

Merged
zzh merged 42 commits from test into master 2026-10-08 09:18:00 +08:00
2 changed files with 22 additions and 2 deletions
Showing only changes of commit a9f8373ec3 - Show all commits

View File

@ -0,0 +1,18 @@
-- 分区明细按 AreaId 全量/分页查询时避免 filesort 打满 sort_buffer(查价 LIVE 路径易踩)
SET @db := DATABASE();
SET @idx := (
SELECT COUNT(1)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_kpi_area_info'
AND INDEX_NAME = 'idx_kpi_info_area_id'
);
SET @sql := IF(
@idx = 0,
'ALTER TABLE `t_kpi_area_info` ADD KEY `idx_kpi_info_area_id` (`AreaId`, `Id`)',
'SELECT ''idx_kpi_info_area_id already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

View File

@ -21,9 +21,10 @@ public class KpiAreaRepository : OmsSqlSugarRepository<KpiArea>, IKpiAreaReposit
public async Task<List<KpiAreaInfo>> GetInfosAsync(int areaId, int pageIndex, int pageSize, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
// 依赖 idx_kpi_info_area_id (AreaId, Id),避免大分区 filesort
return await db.Queryable<KpiAreaInfo>()
.Where(x => x.AreaId == areaId)
.OrderBy(x => x.Id, SqlSugar.OrderByType.Desc)
.OrderBy(x => x.Id, OrderByType.Desc)
.ToPageListAsync(pageIndex, pageSize, cancellationToken);
}
@ -66,9 +67,10 @@ public class KpiAreaRepository : OmsSqlSugarRepository<KpiArea>, IKpiAreaReposit
public async Task<List<KpiAreaInfo>> GetAllInfosByAreaIdAsync(int areaId, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
// 大分区表(如美区邮编)全量 ORDER BY 会打满 MySQL sort_buffer 导致 500;
// 需要稳定顺序的调用方在内存中排序(如 EnsurePackAsync)。
return await db.Queryable<KpiAreaInfo>()
.Where(x => x.AreaId == areaId)
.OrderBy(x => x.Id)
.ToListAsync(cancellationToken);
}