Re: SQL renamed expression name not recognised in WHERE




"Jonathan Ball" <jonball@xxxxxxxxxxxxxx> wrote in message
news:RNwIc.58$mL5.30@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DBDriver wrote:


I'm not sure of a performance issue. I ran both the
OP's original query and my nested table expression
suggestion through VisualExplain in iSeries Navigator,
and the access path used and the method to determine it
were identical. I'll have to try it later today in a
better setting than what I can do from home.


It also depends a lot on the DB involved. By way of example, we encountered
the following recently...

SELECT Xa, Xb, Xc, SUM(Xd)
FROM TableX
GROUP BY Xa, Xb, Xc
HAVING (Xa = Value1) AND (Xb = Value2) AND (Xc = Value3)


Now this query should flounder on a large database if it treats the HAVING
directive as a filter on a derived value only. Reading this literally, the
result set is formed and then the derived "grouped" results are calculated
before they are filtered by the Having statement.

Under SQL Server 2000 this worked perfectly fine (no performance hit).

Under Oracle 9i it nose dived as the table size grew.

We didn't test this under any DB2 variants as it wasn't a supported DB of
the project.

The corrected version (which run equally well under SQL Server and Oracle
9i) was to force the filtering at a lower level (the original resultset).
i.e..

SELECT Xa, Xb, Xc, SUM(Xd)
FROM TableX
WHERE (Xa = Value1) AND (Xb = Value2) AND (Xc = Value3)
GROUP BY Xa, Xb, Xc


The best we can gauge is that the SQL Server was more sensitive to this type
of programming error and correctly applied the "Having" condition back at a
lower level as a record filter. Oracle 9i on the other hand was very literal
in it's interpretation. It should also be noted that on relatively small
tables Oracle ran the original form very quickly!

I am not sure why your DB2 tests didn't reveal any performance discrepancy
but it could indeed be due to the complexity of the where condition
impacting on record selection. You could find, though, that a different
database will not behave in a similar fashion. I know for sure that, in the
case of the subquery example, SQL Server would run this type of query/filter
extremely slowly by comparison to the single select statement.


RJ.


.



Relevant Pages

  • Re: Number to Date.
    ... queries for DBs it took me a long time to build the ... original query for Oracle. ... >1E4/1E2 can not be accepted by sql server as it is. ...
    (microsoft.public.sqlserver.mseq)
  • Re: "DataSet" input parametes to Stored Procedures
    ... I'm not quite familiar with Oracle. ... But in SQL Server, ... database what to update (filter) and how to update. ...
    (microsoft.public.sqlserver.programming)
  • Re: IOT, memory and transaction time
    ... easily generate it with DBMS_METADATA.GET_DDL if your verison of Oracle ... were pretty consistent no matter how big the table (this transaction ... FOREIGN KEY (versionNo) REFERENCES T_TRANSACTIONS, ... Oracle provides read consistency and SQL Server ...
    (comp.databases.oracle.misc)
  • Re: Database or store to handle 30 Mb/sec and 40,000 inserts/sec
    ... "Writers block readers and readers block writers in SQLServer. ... getting around this fundamental issue and because of it SQL Server ... admitted they can happen in Oracle, I guess Oracle should never been used ... isolation level but you will always disagree because you follow doctorine ...
    (comp.databases.oracle.server)
  • Re: IOT, memory and transaction time
    ... easily generate it with DBMS_METADATA.GET_DDL if your verison of Oracle ... If it was the update statement that references ... FOREIGN KEY (versionNo) REFERENCES T_TRANSACTIONS, ... There are however differences how both products deal with concurrency; in Oracle readers don't get blocked while this may happen in SQL Server. ...
    (comp.databases.oracle.misc)