all groups > sql server odbc > october 2004 >
You're in the

sql server odbc

group:

SELECT MAX(...) performance SQL Server/ODBC



SELECT MAX(...) performance SQL Server/ODBC Mehrdad
10/19/2004 1:09:03 PM
sql server odbc: I work on a commercial software product that is a database application. ODBC
database connectivity and MFC record set classes are used to access the
database. The software supports three types of databases - Oracle, Sybase
ASA, and SQL Server. One of our clients has a relatively big SQL Server 2000
SP3a database and they are experience bad performances when data is saved to
the database. The bottleneck for the bad performance appears to be the SELECT
MAX(...) statement that is executed against the table named abw_event.

SELECT MAX(event_id) FROM abw_event;

Here is DDL for the table:

CREATE TABLE abw_event (
event_id int NOT NULL,
prev_event_id int NULL,
event_type int NOT NULL,
on_behalf_of_user int NULL,
entered_by int NULL,
event_timestamp datetime NOT NULL,
event_descr varchar(2000) NULL,
event_message varchar(2000) NULL,
how_long_to_keep smallint NULL
)
go

ALTER TABLE abw_event
ADD CONSTRAINT XPKabw_event PRIMARY KEY NONCLUSTERED (event_id)
go

The abw_event table has 53000 rows in it and its primary key is a single
column with int data type. The C++ code issues the above SELECT MAX(...)
command through ODBC function call "SQLExecDirect" that takes 15+ seconds to
execute.

What's interesting is that if I run the same SELECT MAX(...) command in the
Query Analyzer I get the results instantly. I suspect that this bad
performance has something to do with ODBC driver.

The same SELECT MAX(…) statement executes instantly while using Oracle or
Sybase ASA databases.

I appreciate your feedback.

Thanks,
Mehrdad
SELECT MAX(...) performance SQL Server/ODBC gandalf
10/20/2004 12:54:48 AM
What query-plan does the query analyzer show for=20
SELECT MAX(event_id) FROM abw_event ?

have you updated the odbc drivers with mdac?


[quoted text, click to view]
RE: SELECT MAX(...) performance SQL Server/ODBC Mehrdad
10/20/2004 6:23:06 AM
The query execution plan is something like this:

SELECT <---- Stream Aggregation <---- Top <----
abw_event.XPKabw_event
Cost: 0% Cost: 0% Cost: 0%
Cost: 100%
MAX(abw_event.event_id)
abw_event.XPKabw_event

ORDERED BACKWARD


I have the latest SQL Server driver (version 2000.85.1117.00) dated
8/4/2004. I think the MDAC get updated with Windows XP Update automatically.

Thanks,
Mehrdad

[quoted text, click to view]
AddThis Social Bookmark Button