idh_hist 使用日期搜索时查询速度很慢
idh_hist query is very slow while searching with date
我正在尝试编写查询以通过 MFG/PRO 发票 table 'idh_hist' 搜索特定日期范围。添加日期条件时 运行 非常慢。但是当我推迟日期条件时,它非常快。您能否建议在 idh_hist 上编写查询的方法,该查询在条件下运行得相当快。
以下是我的查询:
for each idh_hist no-lock where idh_domain = "d0002"
and idh_due_date = TODAY:
/* display code here... */
end.
提前致谢!
数据库索引:
Flags Index Name Cnt Field Name
----- --------------------- ---- ---------------------
idh_fsm_type 4 + idh_domain
+ idh_fsm_type
+ idh_nbr
+ idh_line
pu idh_invln 4 + idh_domain
+ idh_inv_nbr
+ idh_nbr
+ idh_line
idh_part 4 + idh_domain
+ idh_part
+ idh_inv_nbr
+ idh_line
u oid_idh_hist 1 + oid_idh_hist
您似乎没有使用 idh_due_date 的索引。您将需要添加这样的索引。
4gl 使用规则select 基于 WHERE 子句的索引。最重要的规则是将使用具有相等匹配项的索引的前导组件。
您显示的查询在 idh_domain 上只有一个这样的匹配项。因此,应用决胜局规则。这将导致选择 idh_invln 索引。
事实上,为了满足您的查询,需要搜索与 "idh_domain" 字段匹配的所有记录。 (如果您只有一个域,则表示您正在进行 table 扫描。)
您可能想在 idh_domain 和 idh_due_date 上添加索引。那将是您查询的完美匹配。
我正在尝试编写查询以通过 MFG/PRO 发票 table 'idh_hist' 搜索特定日期范围。添加日期条件时 运行 非常慢。但是当我推迟日期条件时,它非常快。您能否建议在 idh_hist 上编写查询的方法,该查询在条件下运行得相当快。
以下是我的查询:
for each idh_hist no-lock where idh_domain = "d0002"
and idh_due_date = TODAY:
/* display code here... */
end.
提前致谢!
数据库索引:
Flags Index Name Cnt Field Name
----- --------------------- ---- ---------------------
idh_fsm_type 4 + idh_domain
+ idh_fsm_type
+ idh_nbr
+ idh_line
pu idh_invln 4 + idh_domain
+ idh_inv_nbr
+ idh_nbr
+ idh_line
idh_part 4 + idh_domain
+ idh_part
+ idh_inv_nbr
+ idh_line
u oid_idh_hist 1 + oid_idh_hist
您似乎没有使用 idh_due_date 的索引。您将需要添加这样的索引。
4gl 使用规则select 基于 WHERE 子句的索引。最重要的规则是将使用具有相等匹配项的索引的前导组件。
您显示的查询在 idh_domain 上只有一个这样的匹配项。因此,应用决胜局规则。这将导致选择 idh_invln 索引。
事实上,为了满足您的查询,需要搜索与 "idh_domain" 字段匹配的所有记录。 (如果您只有一个域,则表示您正在进行 table 扫描。)
您可能想在 idh_domain 和 idh_due_date 上添加索引。那将是您查询的完美匹配。