views:

45

answers:

1

I'm experimenting with postgres and sql server

the same query in sql server gives me:

CPU time = 31 ms,  elapsed time = 800 ms.

and in postgres:

38 ms

but when I do the same query via .net using SqlConnection,SqlCommand and NpgsqlConnection,NpgsqlCommand

the sqlserver is 30% faster

can anyone explain this ?

+1  A: 

A quick guess is Npgsql is not as optimized as the Microsoft SQL Server .net connection library. You pretty much proved that when the SQL Server query was 30% faster when invoked via .net. Did you run the test a few times one after another for both databases? Just make sure SQL Server wasn't caching data making it look blazing fast compared to PostgreSQL going out to disk for the same data.

StarShip3000
@StarShip3000 yes I know about this, 2nd time they are both faster (postgres caches also, I guess), but sql server is still 30% faster, doesn't matter 1st time or 2nd, although there is a big difference between 1st and 2nd time you execute the same query
Omu
@Omu Plus you have to keep in mind all the variables at work here. Are both databases on the same hardware? With the same load? Are both configured to be exactly the same? Lot's of possible variables at work here. But it appears that you are showing it probably has to do with the .net drivers. With the SQL Server being more per formant at least under your select * from foo test, which is a really unrealistic query to be running for real world test results. Normally never select *, and it's rare you would select all rows from a table unless you are caching a look up tables values.
StarShip3000
@StarShip3000 servers are exactly the same, anyway that doesn't really matters, because posrgre is much faster than sql server but not via NpgSql,.net
Omu
@Omu have you tried the Devart driver for Postgres? I wouldn't be surprised if it was faster than Npgsql.
Cory Grimster
@Cory Grimster as a matter of fact I did tried it, and it almost 2 times slower, but it does support TransactionScope(), so it is very possible that this is what I'm going to use
Omu