Hi have the following two queries.
QUERY 1
SELECT
count(*)
FROM
OUTST_VIEW outst_view,
CUS_WEIGHTED_FAIRVALUE CUS_WEIGHTED_FAIRVALUE
WHERE
outst_view.NUF_GRANT_NUMBER = CUS_WEIGHTED_FAIRVALUE.FK_GRANT_NUMBER(+)
ORDER BY
outst_view.GRANT_TYPE_BASE ASC,
outst_view.OPTION_PRICE ASC,
outst_view.GRANT_DATE ASC,
CUS_WEIGHTED_FAIRVALUE.WEIGHTED_FAIR_VALUE ASC,
outst_view.GRANT_TYPE ASC
QUERY 2
SELECT
COUNT(*)
FROM
OUTST_VIEW outst_view,
CUS_WEIGHTED_FAIRVALUE CUS_WEIGHTED_FAIRVALUE
WHERE
outst_view.NUF_GRANT_NUMBER = CUS_WEIGHTED_FAIRVALUE.FK_GRANT_NUMBER(+) AND
outst_view.NUF_SAR_TYPE_IF_ALLOWED <> 2 AND
outst_view.NUF_GRANT_TYPE <> 2
ORDER BY
outst_view.GRANT_TYPE_BASE ASC,
outst_view.OPTION_PRICE ASC,
outst_view.GRANT_DATE ASC,
CUS_WEIGHTED_FAIRVALUE.WEIGHTED_FAIR_VALUE ASC,
outst_view.GRANT_TYPE ASC
I am using the count function because I have over 100,000 records in my output.
Both objects in the from clause are views. The OUTST_VIEW selects data from many tables and the US_WEIGHTED_FAIRVALUE view selects data from one table. The outst_view.NUF_GRANT_NUMBER field is indexed in its underlying table and is the primary key of that table. It is also unique in the view. The CUS_WEIGHTED_FAIRVALUE.FK_GRANT_NUMBER field is indexed in its underlying table but is not the primary key.
So when I run both queries in SQL Worksheet the first query runs in about 15 seconds. However I give up on the second query after about two minutes. BTW, in my actual application I am using Crystal Reports, which sends these
queries to the database (COUNT(*) is replaced by the fields used in the report). I really want to stick with the second query.
I thought is was the left outer join but when I run the second query without it, same problem.
Why is this happening?
I hope I have explained my problem correctly.
QUERY 1
SELECT
count(*)
FROM
OUTST_VIEW outst_view,
CUS_WEIGHTED_FAIRVALUE CUS_WEIGHTED_FAIRVALUE
WHERE
outst_view.NUF_GRANT_NUMBER = CUS_WEIGHTED_FAIRVALUE.FK_GRANT_NUMBER(+)
ORDER BY
outst_view.GRANT_TYPE_BASE ASC,
outst_view.OPTION_PRICE ASC,
outst_view.GRANT_DATE ASC,
CUS_WEIGHTED_FAIRVALUE.WEIGHTED_FAIR_VALUE ASC,
outst_view.GRANT_TYPE ASC
QUERY 2
SELECT
COUNT(*)
FROM
OUTST_VIEW outst_view,
CUS_WEIGHTED_FAIRVALUE CUS_WEIGHTED_FAIRVALUE
WHERE
outst_view.NUF_GRANT_NUMBER = CUS_WEIGHTED_FAIRVALUE.FK_GRANT_NUMBER(+) AND
outst_view.NUF_SAR_TYPE_IF_ALLOWED <> 2 AND
outst_view.NUF_GRANT_TYPE <> 2
ORDER BY
outst_view.GRANT_TYPE_BASE ASC,
outst_view.OPTION_PRICE ASC,
outst_view.GRANT_DATE ASC,
CUS_WEIGHTED_FAIRVALUE.WEIGHTED_FAIR_VALUE ASC,
outst_view.GRANT_TYPE ASC
I am using the count function because I have over 100,000 records in my output.
Both objects in the from clause are views. The OUTST_VIEW selects data from many tables and the US_WEIGHTED_FAIRVALUE view selects data from one table. The outst_view.NUF_GRANT_NUMBER field is indexed in its underlying table and is the primary key of that table. It is also unique in the view. The CUS_WEIGHTED_FAIRVALUE.FK_GRANT_NUMBER field is indexed in its underlying table but is not the primary key.
So when I run both queries in SQL Worksheet the first query runs in about 15 seconds. However I give up on the second query after about two minutes. BTW, in my actual application I am using Crystal Reports, which sends these
queries to the database (COUNT(*) is replaced by the fields used in the report). I really want to stick with the second query.
I thought is was the left outer join but when I run the second query without it, same problem.
Why is this happening?
I hope I have explained my problem correctly.