Merge branch 'main' of https://gitee.com/wg123/video-gen
This commit is contained in:
@@ -24,20 +24,21 @@ def upgrade() -> None:
|
|||||||
# ========================================
|
# ========================================
|
||||||
# 2026-07-09 - 生成记录表增加日期表达式索引
|
# 2026-07-09 - 生成记录表增加日期表达式索引
|
||||||
# ========================================
|
# ========================================
|
||||||
# 使用 timezone('utc', generated_at)::date 而不是 date(generated_at):
|
# 使用 CAST(timezone('utc', generated_at) AS date) 而不是 date(generated_at):
|
||||||
# 当 generated_at 为 timestamptz 时,date() 的结果依赖会话时区,属于 STABLE 函数,
|
# 1) 当 generated_at 为 timestamptz 时,date() 的结果依赖会话时区,属于 STABLE 函数,
|
||||||
# 无法用于索引表达式。将时区后设再转 date 在语义上等价于 trunc 到天,
|
# 无法用于索引表达式。显式指定 UTC 时区后转为 date 是纯计算,属于 IMMUTABLE。
|
||||||
# 该表达式是 IMMUTABLE 的,可用于创建函数索引。
|
# 2) 必须用 CAST(... AS date) 而不能用 ::date::: 的优先级高于函数调用,
|
||||||
|
# PG 会把 func(x)::date 解析为 func(x::date),导致语法错误。
|
||||||
op.create_index(
|
op.create_index(
|
||||||
'idx_chat_generation_tasks_generated_date',
|
'idx_chat_generation_tasks_generated_date',
|
||||||
'chat_generation_tasks',
|
'chat_generation_tasks',
|
||||||
[sa.text("timezone('utc', generated_at)::date")],
|
[sa.text("CAST(timezone('utc', generated_at) AS date)")],
|
||||||
unique=False,
|
unique=False,
|
||||||
)
|
)
|
||||||
op.create_index(
|
op.create_index(
|
||||||
'idx_generation_records_generated_date',
|
'idx_generation_records_generated_date',
|
||||||
'generation_records',
|
'generation_records',
|
||||||
[sa.text("timezone('utc', generated_at)::date")],
|
[sa.text("CAST(timezone('utc', generated_at) AS date)")],
|
||||||
unique=False,
|
unique=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user