2016-08-11 37 views
0

我想寫一個查詢,通過MFG/PRO發票表'idh_hist'搜索特定的日期範圍。添加日期條件時,它運行速度非常慢。但是,當我推遲日期條件時,速度非常快。你能否建議在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 
+0

你能和我們分享idh_hist表上的索引定義嗎? –

+0

嗨@MikeFechner,我在這裏添加了索引。謝謝。 –

回答

1

你似乎不具有使用idh_due_date的索引。您需要添加這樣的索引。

4gl使用規則根據WHERE子句選擇索引。最重要的規則是使用具有相等匹配的索引的主要組件。

您僅顯示的查詢在idh_domain上有一個這樣的匹配。那麼就應用打破僵局的規則。這將導致選擇idh_invln索引。

事實上,爲了滿足您的查詢,需要搜索與「idh_domain」字段匹配的所有記錄。 (如果您只有一個域,表示您正在進行表掃描。)

您可能想要在idh_domain和idh_due_date上添加索引。這將是您的查詢完美匹配。

+0

非常感謝@湯姆。順便說一下,我可以在QAD標準表中添加自定義索引嗎? –

+0

這樣做沒有技術障礙。只有FUD會阻止你。 –