-- =================================================================== -- 20260504 — cfg_* 视图 NULL 兼容性 + 清理重复 WHERE bug -- =================================================================== -- 触发:Wave 1 W1-T2(P0-1 沙箱配置参数切片) -- -- 问题: -- 1. 20260502 迁移产出的 4 个 v_cfg_* 视图 WHERE 写为 -- effective_to >= app.business_date_now() -- effective_to 是 nullable(NULL 表示"至今仍生效"),NULL 行被过滤, -- cfg_index_parameters 27 行参数中 effective_to IS NULL 的全部丢失。 -- 2. v_cfg_assistant_level_price 与 v_cfg_performance_tier 的 WHERE -- 条件重复一次(逻辑等价,但代码瑕疵)。 -- -- 修复: -- ALTER VIEW(实际 CREATE OR REPLACE)4 个视图,WHERE 改为 -- effective_from <= app.business_date_now() -- AND (effective_to IS NULL OR effective_to >= app.business_date_now()) -- -- 影响: -- - ETL 任务通过 app.v_cfg_* 读取时,正确包含 effective_to IS NULL 行。 -- - 后端通过 FDW 映射访问 fdw_etl.v_cfg_* 时同步生效(底层视图变更)。 -- - 沙箱模式下,app.business_date_now() 返回 sandbox_date,自动切片。 -- -- 回滚: -- - 重新执行 20260502 迁移的 4 个 CREATE OR REPLACE VIEW 部分即可。 -- -- 验证 SQL: -- 1. SELECT COUNT(*) FROM app.v_cfg_index_parameters WHERE index_type='SPI'; -- 应等于 27(测试库实际值)。 -- 2. SELECT COUNT(*) FROM dws.cfg_index_parameters WHERE index_type='SPI' -- AND effective_from <= CURRENT_DATE -- AND (effective_to IS NULL OR effective_to >= CURRENT_DATE); -- 应与 1 的结果相同。 -- 3. SET LOCAL app.current_business_date = '2026-03-01'; -- SELECT COUNT(*) FROM app.v_cfg_index_parameters WHERE index_type='SPI'; -- 切沙箱时间后,行数应等于 2026-03-01 当时生效的参数数量。 -- =================================================================== BEGIN; -- ---- v_cfg_assistant_level_price ---- CREATE OR REPLACE VIEW app.v_cfg_assistant_level_price AS SELECT price_id, level_code, level_name, base_course_price, bonus_course_price, effective_from, effective_to, description, created_at, updated_at FROM dws.cfg_assistant_level_price WHERE effective_from <= app.business_date_now() AND (effective_to IS NULL OR effective_to >= app.business_date_now()); -- ---- v_cfg_performance_tier ---- CREATE OR REPLACE VIEW app.v_cfg_performance_tier AS SELECT tier_id, tier_code, tier_name, tier_level, min_hours, max_hours, base_deduction, bonus_deduction_ratio, vacation_days, vacation_unlimited, is_new_hire_tier, effective_from, effective_to, description, created_at, updated_at FROM dws.cfg_performance_tier WHERE effective_from <= app.business_date_now() AND (effective_to IS NULL OR effective_to >= app.business_date_now()); -- ---- v_cfg_bonus_rules ---- CREATE OR REPLACE VIEW app.v_cfg_bonus_rules AS SELECT rule_id, rule_type, rule_code, rule_name, threshold_hours, rank_position, bonus_amount, is_cumulative, priority, effective_from, effective_to, description, created_at, updated_at FROM dws.cfg_bonus_rules WHERE effective_from <= app.business_date_now() AND (effective_to IS NULL OR effective_to >= app.business_date_now()); -- ---- v_cfg_index_parameters ---- CREATE OR REPLACE VIEW app.v_cfg_index_parameters AS SELECT param_id, index_type, param_name, param_value, description, effective_from, effective_to, created_at, updated_at FROM dws.cfg_index_parameters WHERE effective_from <= app.business_date_now() AND (effective_to IS NULL OR effective_to >= app.business_date_now()); COMMIT;