Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-10 Thread Yuzem
Hi, thanks a lot for the helpful replies. Sorry to bother again, but there is still something that hasn't been answered. Simon Slavin-3 has addressed my question but not exactly what I was asking. Suppose I have two tables "movies" and "people" and other tables to relate both tables:

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread BareFeetWare
You have: CREATE TABLE movies(movie_id INTEGER, title TEXT, unique(movie_id)); CREATE TABLE tags(movie_id INTEGER, tag TEXT, unique(movie_id,tag)); You can solve your problem, using pure SQL. No need to resort to the application layer. Just execute the SQL transaction below. It takes care of

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Simon Slavin
On 7 Feb 2011, at 11:19pm, Yuzem wrote: > One more thing: > I have the tables "movies" and "people" > Those two tables are related by tables "directors", "writers", etc... > movies: id, title > people: id, name > > directors: movieId, peopleId > writers: movieId, peopleId > etc... > > How can

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Yuzem
Ok, thanks all for your answers, I guest I will have to normalize the database and explore the foreign key feature. One more thing: I have the tables "movies" and "people" Those two tables are related by tables "directors", "writers", etc... movies: id, title people: id, name directors:

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Pavel Ivanov
2     0     tags           00 > 21    Goto           0     5     0                    00 > > Michael D. Black > Senior Scientist > NG Information Systems > Advanced Analytics Directorate > > > > > From: sqlite-users-boun..

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Black, Michael (IS)
Directorate From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Yuzem [naujnit...@gmail.com] Sent: Monday, February 07, 2011 2:13 PM To: sqlite-users@sqlite.org Subject: Re: [sqlite] EXT : Speed up count(distinct col) Bl

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Eric Smith
Yuzem wrote: > > > > Test#1 > > create index tags_index on tags(tag); > > You should have an index for any fields you query on like this. > > > > Thanks Michael but I don't see any speed improvement: > create index test on tags(tag); > select count(distinct tag) from tags; > > This is much

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Yuzem
Black, Michael (IS) wrote: > > Test#1 > create index tags_index on tags(tag); > You should have an index for any fields you query on like this. > Thanks Michael but I don't see any speed improvement: create index test on tags(tag); select count(distinct tag) from tags; This is much faster:

Re: [sqlite] EXT : Speed up count(distinct col)

2011-02-07 Thread Black, Michael (IS)
Test#1 create index tags_index on tags(tag); You should have an index for any fields you query on like this. Test#2 Normalize your tags into a separate table so you then store the rowid in your tags table instead of the string. Your compares will be notably faster using integers rather than