This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rute
Recipients doko, erno, ghaering, gregburd, gregory.p.smith, jcea, josiahcarlson, pitrou, rhettinger, rute, skip.montanaro
Date 2009-11-19.16:56:48
SpamBayes Score 1.4214187e-05
Marked as misclassified No
Message-id <1258649811.04.0.548309632722.issue3783@psf.upfronthosting.co.za>
In-reply-to
Content
By utilizing triggers on inserts and deletes it is possible to
keep track of the size and speed up __len__ by 10 x.

SQL:

CREATE TABLE IF NOT EXISTS info
   (key TEXT UNIQUE NOT NULL,
    value INTEGER NOT NULL);

INSERT OR IGNORE INTO info (key,value) VALUES ('size',0);

CREATE TABLE IF NOT EXISTS shelf
    (key TEXT UNIQUE NOT NULL,
     value TEXT NOT NULL);

CREATE TRIGGER IF NOT EXISTS insert_shelf
    AFTER INSERT ON shelf
    BEGIN
         UPDATE info SET value = value + 1 WHERE key = 'size';
    END;

CREATE TRIGGER IF NOT EXISTS delete_shelf
    AFTER DELETE ON shelf
    BEGIN
         UPDATE info SET value = value - 1 WHERE key = 'size';
    END;

On my laptop this increase the speed of 'len' about 10x

I have a slightly modified version of dbsqlite.py for
running on python 2.5 utilizing the triggers for 
keep track of the size:

http://dpaste.com/hold/122439/
History
Date User Action Args
2009-11-19 16:56:51rutesetrecipients: + rute, skip.montanaro, rhettinger, doko, gregory.p.smith, jcea, ghaering, josiahcarlson, pitrou, erno, gregburd
2009-11-19 16:56:51rutesetmessageid: <1258649811.04.0.548309632722.issue3783@psf.upfronthosting.co.za>
2009-11-19 16:56:48rutelinkissue3783 messages
2009-11-19 16:56:48rutecreate