开发者

Anything faster than SELECT DISTINCT item FROM DB?

Is there any alternative to

SELECT DISTINCT item FROM DB 

I have already tried:

SELECT item FROM DB group by item 

the table isn't so large (30,000 开发者_如何学Gorows) but this command takes almost 6 seconds to complete. On the other hand, other queries perform very fast (0.2 seconds).

What might be going on? Suggestions?

By the way, this is how I am using it in my program:

BDD.addItems([r[0] for r in cursor.execute("SELECT DISTINCT commodity FROM DB")])


make sure there is an index on the distinct column


0.1 is a WAY too much.

You shouldn't use distinct for the resource-critical queries.
You have to normalize your database instead, storing whatever items in a separate table, leaving only links to them in the original table.

And count these items from this other table. Properly indexed, it will take less than 0.01

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜