Roundup Tracker - Issues

Message1428

Author anonymous
Recipients
Date 2004-08-20.09:14:26
Message-id
In-reply-to
Sometimes the full text search creates queries of the
following form (1):

select distinct(id) from _issue, issue_files,
issue_messages where __retired__ <> %s and
(((id=issue_files.nodeid and issue_files.linkid in
(%s))) or ((id=issue_messages.nodeid and
issue_messages.linkid in (%s,...,%s))))

and sometimes of this form (2):

select distinct(id) from _issue, issue_messages where
__retired__ <> %s and id=issue_messages.nodeid and
issue_messages.linkid in (%s,...,%s))

Form (1) queries are extremely inefficient and can take
minutes to execute (at least with the sqlite backend).
Here is an example query that can be tested using the
sqlite command line:

select distinct(id) from _issue, issue_files,
issue_messages where __retired__ <> 1 and
(((id=issue_files.nodeid and issue_files.linkid in
('4'))) or ((id=issue_messages.nodeid and
issue_messages.linkid in ('1789'))));

The query is slow because it is fetching the cartesian
product of issue_files and issue_messages which takes a
lot of time.

However, when I split it into two queries:

select id from _issue, issue_files where __retired__ <>
1 and (((id=issue_files.nodeid and issue_files.linkid
in ('4'))));

select id from _issue, issue_messages where __retired__
<> 1 and (((id=issue_messages.nodeid and
issue_messages.linkid in ('1789'))));

I can leave the "distinct" away and both queries return
in practically zero time.

Using "union", we can put the two queries together into
a single efficient one again:

select id from _issue, issue_files where __retired__ <>
1 and (((id=issue_files.nodeid and issue_files.linkid
in ('4')))) union select id from _issue, issue_messages
where __retired__ <> 1 and (((id=issue_messages.nodeid
and issue_messages.linkid in ('1789'))));
History
Date User Action Args
2009-02-03 14:20:55adminlinkissue1012781 messages
2009-02-03 14:20:55admincreate