UPDATE communalgoodextend
SET GoodsSaleLevel = 2
WHERE
Id IN (
SELECT
GoodsId
FROM
(
SELECT
*,
@hnum := @hnum + 1 AS hnum
FROM
(
SELECT
*,
RANK() OVER ( PARTITION BY GoodClassId ORDER BY SaleNum ASC ) AS rownum
FROM
(
SELECT
a.GoodsId,
b.GoodClassId,
COALESCE ( SUM( a.SaleNum - a.SaleReturnNum ), 0 ) AS SaleNum
FROM
purchasestocksaledaily a
INNER JOIN communalgood b ON a.GoodsId = b.Id
WHERE
a.TenantId = 2
AND b.AffiliationBusinessformatId = ‘3a149ea7-b4fe-9fe0-dcd4-b26819688fa1’
AND a.ReportDate >= ‘2024-11-19’
AND a.ReportDate < ‘2024-12-19’
GROUP BY
a.GoodsId,
b.GoodClassId
) AS a,(
SELECT
@hnum := 0
) AS b
) AS c
ORDER BY
rownum
) AS d
WHERE
d.hnum <=(
@hnum * 0.1)
);
直接执行in里面的子查询很快,其实能查到的数据是0行,但是update语句一执行就卡住,一直执行到最大超时时间就挂了。
Oceanbase版本:5.7.25-OceanBase_CE-v4.3.0.1
表结构:
Oceanbase执行超时表结构.txt (16.4 KB)
我在一个新的数据库创建了表结构空数据下在执行这个update语句没有重现问题,很快就执行完。
数据量:
communalgoodextend:17920
communalgood:17920
purchasestocksaledaily:112194