Страница 1 из 1

Оптимизировать условие в VIEW

Добавлено: 27 мар 2007, 10:19
Konstantin
Есть вьюшка в ней условие.
Where
( ( createuserid = (select id from username where name = current_user ))
OR (touserid = (select id from username where name = current_user )))
or (exists (select 1 from username where name = current_user and read_other = 1))
or ( touserid = 0)
or (togroupid = (select usertogroup.groupid from username, usertogroup where name = current_user
and username.id = usertogroup.userid))

как можно оптимизировать?

пробовал вот так
ничего не поменялось
( (createuserid = (select id from username where name = current_user ))
OR (touserid IN( (select id from username where name = current_user ), 0)))
or (exists (select 1 from username where name = current_user and read_other = 1))
-- or (touserid = 0)
or (togroupid = (select usertogroup.groupid from username, usertogroup where name = current_user
and username.id = usertogroup.userid))

Добавлено: 27 мар 2007, 10:42
kdv
не мучайся с view, используй процедуру.
www.ibase.ru/devinfo/treedb2.htm

Добавлено: 28 мар 2007, 13:43
Konstantin
Прочитал статью.
перевел все в процедуру.
при запросе Select * from View where id =2234
в IBExperte Анализ производительности количество записей в главной таблице = 1

тоже самое в процедуре
количество записей чтения в таблице все.
единственно что изменил условиена прямые значение

WHERE

( (createuserid = :iUserID)
OR (touserid = :iUserID))
or (:IREAD = 1)
or ( touserid = 0)
or (togroupid = :iGroupID)

Так что остался на View