在 FOR EACH WHERE 子句中使用 LOOKUP 是否合适?- 进步4GL

Bha*_*rat 0 progress-4gl openedge

如果我们在每个 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
Run Code Online (Sandbox Code Playgroud)

Ste*_*sen 6

查找函数不能使用索引,所以是的,您可以引入可以避免的低于标准的性能。请参阅以下使用体育数据库的示例,该数据库将在使用查找时读取所有记录,并在将部分分解为单独的查询部分时将集合限制为满足条件:

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.
Run Code Online (Sandbox Code Playgroud)

https://abldojo.services.progress.com/?shareId=6272e1223fb02369b2545bf4

然而,您的示例似乎正在执行反向查找,即数据库字段包含逗号分隔的值列表,这似乎不遵守数据库规范化的基本规则。

如果您想将列表保留在单个字段中,在逗号分隔字段上添加单词索引可能会有所帮助。然后您可以使用contains