我怎样才能使数据库访问快速进行 4gl
How can i make database access fast of progress 4gl
我必须快速访问包含大量唯一索引数据的数据库 mstr_nbr 我怎样才能让它更快。
其中第一个 mstr 花费 0ms
获取下一个 mstr 大部分时间为 0ms,但有时需要 1ms
意味着每次 mstr 运行 180000 12000 次运行需要 1 毫秒,这会增加时间,如果没有串行循环增加,每次 12000 毫秒也会增加,这是一个 webspeed 生成的网页,我怎样才能让它变得更快......任何人帮助
DEFINE QUERY Mstr FOR mstr scrolling.
OPEN QUERY Mstr FOR EACH mstr no-lock
where (Mstr_status = "close" or Mstr_status = "closed").
FOR EACH serial
WHERE (serial_pallet = f_pallet AND serial_f_chr11 <> "BOX")
or (serial_key begins f_pallet)
NO-LOCK BREAK BY serial_pallet by serial_parent by serial__chr11 QUERY-TUNING(LOOKAHEAD CACHE-SIZE 32768 DEBUG EXTENDED):
GET FIRST Mstr.
define variable roID as rowid no-undo.
roID = rowid(mstr).
DO WHILE NOT QUERY-OFF-END('Mstr'):
for each det fields(detnbr detmodel detlot detqty) no-lock
where (detnbr = mstr_nbr) and (detmodel = serial_parent and detlot = serial__chr11):
tinspected = tinspected + detqty.
end. /* for each */
GET NEXT Mstr.
END.
reposition mstr to rowid roID.
end.
mstr 索引 table
index-name field-name
badgenew 1 badgenew Active
datenew 1 datenew Active
nbridx 1 nbr Unique Primary Active
pallet 1 pallet Active
proddesc 1 proddesc Active
prodline 1 prodline Active
status 1 status Active
type 1 type Active
table 序列的索引:
actual_prod_day 1 dte04 2 serial_chr01 Active
actual_prod_line 1 serial_pallet 2 serial_dte04 3 serial_chr01 4 serial_line Active
pallet_prod 1 serial_pallet 2 serial_dte04 Active
pallet_prod_line 1 serial_pallet 2 serial_dte04 3 serial_line Active
serial_chr01 1 serial_chr01 Active
serial_chr05 1 serial_chr05 Active
serial_chr06 1 serial_chr06 Active
serial_chr11 1 serial_chr11 Active
serial_chr14 1 serial_chr14 Active
serial_dte04 1 serial_dte04 Active
serial_int01 1 serial_int01 Active
serial_line 1 serial_line Active
serial_pallet 1 serial_pallet Active
serial_parent 1 serial_parent Active
serial_serial__key 1 serial_serial__key 2 serial_parent Unique Primary Active
serial_pallet serial_key和serial_c11都是字符数据类型
索引 table det:
detidx 1 detnbr 2 detpallet 3 detprodline 4 detbox 5 detlot 6 detshift Unique Primary Active
detlot 1 detlot Active
detmodel 1 detmodel Active
detnbr 1 detnbr Active
detpallet 1 detpallet Active
detprodline 1 detprodline Active
鉴于我们所知道的,这就是我的编码方式:
define temp-table tt_mstr
field mstr_nbr as integer /* or whatever the proper data type is */
index mstr_nbr-idx is primary unique /* I am assuming mstr_nbr is unique */
.
for each mstr no-lock
where mstr.mstr_status = "close"
or mstr.mstr_status = "closed":
create tt_mstr.
tt_mstr.mstr_nbr = mstr.mstr_nbr.
end.
for each serial no-lock
where ( serial_pallet = f_pallet and serial_f_chr11 <> "box" ) /* <> "box" is going to perform poorly, there may be better ways to do this */
or ( serial_key begins f_pallet ):
/* break by serial_pallet by serial_parent by serial__chr11: ** this sort of pointless, you're just adding up "tinspected", the order and the break groups have no impact */
for each det fields( detnbr detmodel detlot detqty ) no-lock
where detmodel = serial_parent and detlot = serial__chr11:
find tt_mstr where tt_mstr.mstr_nbr = detnbr no-error.
if available tt_mstr then
tinspected = tinspected + detqty.
end.
end.
使用 temp-table 可避免在“连续”table.
的每次迭代中重新获取所有“关闭”和“关闭”记录
也许缺少某些上下文,但滚动查询和行的重新定位似乎毫无意义。
“串行”记录的 selection 看起来效率不高,但我需要知道哪些索引可用以及 serial_pallet serial_key 和 serial_c11 看起来像。如果只有几个离散值,可能会有更好的写法。
您在每个字段 serial_pallet、serial_f_chr11 和 serial_key 上都有单个组件索引。所以那里没有太多帮助。
这是猜测,但是 如果 serial_f_chr11 中离散值的数量很小,你可能会更好一系列相等匹配和或。假设有效值为 BOX、JAR、BAG 和 LOOSE。在那种情况下,而不是:
where ( serial_pallet = f_pallet and serial_f_chr11 <> "box" )
or ( serial_key begins f_pallet )
你可以这样写:
where ( serial_pallet = f_pallet and serial_f_chr11 = "jar" )
or ( serial_pallet = f_pallet and serial_f_chr11 = "bag" )
or ( serial_pallet = f_pallet and serial_f_chr11 = "loose" )
or ( serial_key begins f_pallet )
如果您在 serial_pallet + serial_f_chr11 上有一个复合索引,那就更好了。
如果离散有效 serial_f_chr11 值的数量较大,或者可能会添加新值,那么最好将它们添加到临时 table 并加入其中。
另一种选择是,不是遍历所有主记录来查找匹配的详细信息,select 首先匹配连续出版物的详细信息。然后找到合适的主记录。这消除了整个循环层。但这取决于“det”table 中的适当索引。您必须有一个以 serial_parent 和 delot 作为前导组件的索引。
如果 mstr_nbr 与“nbr”不是同一个字段(如您的索引列表中所示),那么您需要构建 TT 并在 mstr_nbr 上添加索引。但是,如果 nbr 实际上与 mstr_nbr 相同,那么您可以跳过 TT 并直接有效地查询数据库 table。
我必须快速访问包含大量唯一索引数据的数据库 mstr_nbr 我怎样才能让它更快。 其中第一个 mstr 花费 0ms 获取下一个 mstr 大部分时间为 0ms,但有时需要 1ms 意味着每次 mstr 运行 180000 12000 次运行需要 1 毫秒,这会增加时间,如果没有串行循环增加,每次 12000 毫秒也会增加,这是一个 webspeed 生成的网页,我怎样才能让它变得更快......任何人帮助
DEFINE QUERY Mstr FOR mstr scrolling.
OPEN QUERY Mstr FOR EACH mstr no-lock
where (Mstr_status = "close" or Mstr_status = "closed").
FOR EACH serial
WHERE (serial_pallet = f_pallet AND serial_f_chr11 <> "BOX")
or (serial_key begins f_pallet)
NO-LOCK BREAK BY serial_pallet by serial_parent by serial__chr11 QUERY-TUNING(LOOKAHEAD CACHE-SIZE 32768 DEBUG EXTENDED):
GET FIRST Mstr.
define variable roID as rowid no-undo.
roID = rowid(mstr).
DO WHILE NOT QUERY-OFF-END('Mstr'):
for each det fields(detnbr detmodel detlot detqty) no-lock
where (detnbr = mstr_nbr) and (detmodel = serial_parent and detlot = serial__chr11):
tinspected = tinspected + detqty.
end. /* for each */
GET NEXT Mstr.
END.
reposition mstr to rowid roID.
end.
mstr 索引 table
index-name field-name
badgenew 1 badgenew Active
datenew 1 datenew Active
nbridx 1 nbr Unique Primary Active
pallet 1 pallet Active
proddesc 1 proddesc Active
prodline 1 prodline Active
status 1 status Active
type 1 type Active
table 序列的索引:
actual_prod_day 1 dte04 2 serial_chr01 Active
actual_prod_line 1 serial_pallet 2 serial_dte04 3 serial_chr01 4 serial_line Active
pallet_prod 1 serial_pallet 2 serial_dte04 Active
pallet_prod_line 1 serial_pallet 2 serial_dte04 3 serial_line Active
serial_chr01 1 serial_chr01 Active
serial_chr05 1 serial_chr05 Active
serial_chr06 1 serial_chr06 Active
serial_chr11 1 serial_chr11 Active
serial_chr14 1 serial_chr14 Active
serial_dte04 1 serial_dte04 Active
serial_int01 1 serial_int01 Active
serial_line 1 serial_line Active
serial_pallet 1 serial_pallet Active
serial_parent 1 serial_parent Active
serial_serial__key 1 serial_serial__key 2 serial_parent Unique Primary Active
serial_pallet serial_key和serial_c11都是字符数据类型
索引 table det:
detidx 1 detnbr 2 detpallet 3 detprodline 4 detbox 5 detlot 6 detshift Unique Primary Active
detlot 1 detlot Active
detmodel 1 detmodel Active
detnbr 1 detnbr Active
detpallet 1 detpallet Active
detprodline 1 detprodline Active
鉴于我们所知道的,这就是我的编码方式:
define temp-table tt_mstr
field mstr_nbr as integer /* or whatever the proper data type is */
index mstr_nbr-idx is primary unique /* I am assuming mstr_nbr is unique */
.
for each mstr no-lock
where mstr.mstr_status = "close"
or mstr.mstr_status = "closed":
create tt_mstr.
tt_mstr.mstr_nbr = mstr.mstr_nbr.
end.
for each serial no-lock
where ( serial_pallet = f_pallet and serial_f_chr11 <> "box" ) /* <> "box" is going to perform poorly, there may be better ways to do this */
or ( serial_key begins f_pallet ):
/* break by serial_pallet by serial_parent by serial__chr11: ** this sort of pointless, you're just adding up "tinspected", the order and the break groups have no impact */
for each det fields( detnbr detmodel detlot detqty ) no-lock
where detmodel = serial_parent and detlot = serial__chr11:
find tt_mstr where tt_mstr.mstr_nbr = detnbr no-error.
if available tt_mstr then
tinspected = tinspected + detqty.
end.
end.
使用 temp-table 可避免在“连续”table.
的每次迭代中重新获取所有“关闭”和“关闭”记录也许缺少某些上下文,但滚动查询和行的重新定位似乎毫无意义。
“串行”记录的 selection 看起来效率不高,但我需要知道哪些索引可用以及 serial_pallet serial_key 和 serial_c11 看起来像。如果只有几个离散值,可能会有更好的写法。
您在每个字段 serial_pallet、serial_f_chr11 和 serial_key 上都有单个组件索引。所以那里没有太多帮助。
这是猜测,但是 如果 serial_f_chr11 中离散值的数量很小,你可能会更好一系列相等匹配和或。假设有效值为 BOX、JAR、BAG 和 LOOSE。在那种情况下,而不是:
where ( serial_pallet = f_pallet and serial_f_chr11 <> "box" )
or ( serial_key begins f_pallet )
你可以这样写:
where ( serial_pallet = f_pallet and serial_f_chr11 = "jar" )
or ( serial_pallet = f_pallet and serial_f_chr11 = "bag" )
or ( serial_pallet = f_pallet and serial_f_chr11 = "loose" )
or ( serial_key begins f_pallet )
如果您在 serial_pallet + serial_f_chr11 上有一个复合索引,那就更好了。
如果离散有效 serial_f_chr11 值的数量较大,或者可能会添加新值,那么最好将它们添加到临时 table 并加入其中。
另一种选择是,不是遍历所有主记录来查找匹配的详细信息,select 首先匹配连续出版物的详细信息。然后找到合适的主记录。这消除了整个循环层。但这取决于“det”table 中的适当索引。您必须有一个以 serial_parent 和 delot 作为前导组件的索引。
如果 mstr_nbr 与“nbr”不是同一个字段(如您的索引列表中所示),那么您需要构建 TT 并在 mstr_nbr 上添加索引。但是,如果 nbr 实际上与 mstr_nbr 相同,那么您可以跳过 TT 并直接有效地查询数据库 table。