Hi,

On 8/12/07, Simon Greenhill <[EMAIL PROTECTED]> wrote:
> I'm trying to work out if Ticket #5030 is good to go or not.
> Basically, when save() is called on a model, django does a SELECT
> COUNT(*)... query to check that the primary key is good.
>
> However, SELECT 1... is apparently quite a bit faster in many
> circumstances, and we should use it if we can. It looks like postgres,
> mysql, and sqlite all handle this nicely, but we're not sure about SQL
> Server and Oracle. If anyone knows, or can apply the patch and check,
> please let me know.

Oracle is OK with this. Here are the execution plans for the two methods:

CREATE TABLE ABC ( ID NUMBER(10) NOT NULL, BLAH VARCHAR2(30) );
ALTER TABLE ABC ADD CONSTRAINT PK_ABC PRIMARY KEY (ID);
INSERT INTO ABC VALUES (1,'ZZZ') ;
INSERT INTO ABC VALUES (2,'WWW') ;

SELECT COUNT(*) FROM ABC WHERE ID = 2;

SELECT STATEMENT Optimizer Mode=CHOOSE
  SORT AGGREGATE
    INDEX UNIQUE SCAN   V71MIKEC.PK_ABC
                                                
SELECT 1 FROM ABC WHERE ID = 2;
SELECT STATEMENT Optimizer Mode=CHOOSE
  INDEX UNIQUE SCAN     V71MIKEC.PK_ABC

You'll see that the "SELECT 1" doesn't do the "SORT AGGREGATE", which
shouldn't be all that expensive on a single row, but I suppose any
weight off of the RDBMS is a good thing.

Michael

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to