在 FOR EACH WHERE 子句中使用 LOOKUP 好吗? - 进步 4GL
Is it good to use LOOKUP in FOR EACH WHERE clause? - Progress 4GL
如果我们在每个 where 子句中使用查找函数好吗?它会导致性能问题吗?请帮助理解并提供示例如何避免。
define variable cGroupID as character no-undo.
for each <table> no-lock where lookup(cGroupID,<table.fieldname>) <> 0:
**do something...**
end.
note - table field name can have multiple comma separated group
查找函数不能使用索引,所以是的,您可以引入 sub-par 可以避免的性能。请参阅以下使用体育数据库的示例,该数据库将在使用查找时读取所有记录,并在将部分分解为单个查询部分时将集合限制为满足条件的内容:
def var ii as int no-undo.
def var iread as int64 no-undo.
function reads returns int64:
find _file where _file._file-name = 'customer' no-lock.
find _tablestat where _tablestat._tablestat-id = _file._file-number no-lock.
return _tablestat._tablestat-read.
end function.
iread = reads().
for each customer
where lookup( customer.salesrep, 'dkp,sls' ) > 0
no-lock:
ii = ii + 1.
end.
message 'lookup - records:' ii 'read:' reads() - iread.
ii = 0.
iread = reads().
for each customer
where customer.salesrep = 'dkp'
or customer.salesrep = 'sls'
no-lock:
ii = ii + 1.
end.
message 'or - records:' ii 'read:' reads() - iread.
https://abldojo.services.progress.com/?shareId=6272e1223fb02369b2545bf4
然而,您的示例似乎在执行反向查找,即数据库字段包含逗号分隔的值列表,这似乎不遵守数据库规范化的基本规则。
如果您想将列表保留在单个字段中,在逗号分隔字段中添加单词索引可能会有所帮助。然后您可以使用 contains.
如果我们在每个 where 子句中使用查找函数好吗?它会导致性能问题吗?请帮助理解并提供示例如何避免。
define variable cGroupID as character no-undo.
for each <table> no-lock where lookup(cGroupID,<table.fieldname>) <> 0:
**do something...**
end.
note - table field name can have multiple comma separated group
查找函数不能使用索引,所以是的,您可以引入 sub-par 可以避免的性能。请参阅以下使用体育数据库的示例,该数据库将在使用查找时读取所有记录,并在将部分分解为单个查询部分时将集合限制为满足条件的内容:
def var ii as int no-undo.
def var iread as int64 no-undo.
function reads returns int64:
find _file where _file._file-name = 'customer' no-lock.
find _tablestat where _tablestat._tablestat-id = _file._file-number no-lock.
return _tablestat._tablestat-read.
end function.
iread = reads().
for each customer
where lookup( customer.salesrep, 'dkp,sls' ) > 0
no-lock:
ii = ii + 1.
end.
message 'lookup - records:' ii 'read:' reads() - iread.
ii = 0.
iread = reads().
for each customer
where customer.salesrep = 'dkp'
or customer.salesrep = 'sls'
no-lock:
ii = ii + 1.
end.
message 'or - records:' ii 'read:' reads() - iread.
https://abldojo.services.progress.com/?shareId=6272e1223fb02369b2545bf4
然而,您的示例似乎在执行反向查找,即数据库字段包含逗号分隔的值列表,这似乎不遵守数据库规范化的基本规则。
如果您想将列表保留在单个字段中,在逗号分隔字段中添加单词索引可能会有所帮助。然后您可以使用 contains.