dimanche 12 avril 2015

SQLITE3 - Why is counting 'null' records over a 100x faster than counting 'not null' records in an indexed column?

I have a table with 300,000 rows, with an indexed column being either a large text block or NULL. Currently around 250,000 rows are NULL, with the other 50,000 rows filled with text.


c.execute('SELECT count(indexed_column) FROM table WHERE indexed_column IS NULL)


This does a row count in under one second.


c.execute('SELECT count(indexed_column) FROM table WHERE indexed_column IS NOT NULL)


c.execute('SELECT count(indexed_column) FROM table)


Both of these statements take around 180 seconds each to do their counts.


Why is there such a huge speed discrepancy for identifying NULL values vs NOT NULL? Is there a faster way to count NOT NULL values?


Aucun commentaire:

Enregistrer un commentaire