Jonas:
Thanks for the response. The ticket you referenced refers to __iexact. In
that case, I agree with the use of UPPER. My question/suggestion is about
__icontains, which must either use '...LIKE UPPER()' or ILIKE. In my quick
tests, ILIKE wins by about 10% on a table with 1 million records. ILIKE gets
better the more columns you're comparing, too (30% better, in my example). See
my examples below.
Anyway, I changed it in my implementation because it helped significantly in my
specific case. Hope this helps.
thanks
ted
sdb=# explain analyze select * from activity where msg ilike '%exploit abc
akndkf%';
QUERY
PLAN
--------------------------------------------------------------------------------------------------------------
Seq Scan on activity (cost=0.00..42147.00 rows=1 width=192) (actual
time=1802.493..1802.493 rows=0 loops=1)
Filter: ((msg)::text ~~* '%exploit abc akndkf%'::text)
Total runtime: 1802.553 ms
(3 rows)
sdb=# explain analyze select * from activity where upper(msg) like
upper('%exploit abc akndkf%');
QUERY
PLAN
----------------------------------------------------------------------------------------------------------------
Seq Scan on activity (cost=0.00..44647.00 rows=100 width=192) (actual
time=2074.101..2074.101 rows=0 loops=1)
Filter: (upper((msg)::text) ~~ '%EXPLOIT ABC AKNDKF%'::text)
Total runtime: 2074.158 ms
(3 rows)
sdb=# explain analyze select * from activity where msg ilike '%123%' or
text_src ilike '%123%' or text_dst ilike '%123%' order by msg;
QUERY
PLAN
-----------------------------------------------------------------------------------------------------------------------------------
Sort (cost=48622.98..48646.30 rows=9327 width=192) (actual
time=2241.154..2270.481 rows=3774 loops=1)
Sort Key: msg
Sort Method: external merge Disk: 808kB
-> Seq Scan on activity (cost=0.00..47147.00 rows=9327 width=192) (actual
time=11.701..2178.329 rows=3774 loops=1)
Filter: (((msg)::text ~~* '%123%'::text) OR ((text_src)::text ~~*
'%123%'::text) OR ((text_dst)::text ~~* '%123%'::text))
Total runtime: 2298.757 ms
(6 rows)
sdb=# explain analyze select * from activity where upper(msg) like
upper('%123%') or upper(text_src) like upper('%123%') or upper(text_dst) like
upper('%123%') order by msg;
QUERY
PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=85617.58..85905.74 rows=115264 width=192) (actual
time=3117.558..3147.699 rows=3774 loops=1)
Sort Key: msg
Sort Method: external merge Disk: 808kB
-> Seq Scan on activity (cost=0.00..54647.00 rows=115264 width=192)
(actual time=8.239..3064.163 rows=3774 loops=1)
Filter: ((upper((msg)::text) ~~ '%123%'::text) OR
(upper((text_src)::text) ~~ '%123%'::text) OR (upper((text_dst)::text) ~~
'%123%'::text))
Total runtime: 3177.240 ms
(6 rows)
----- Original Message -----
From: Jonas H. <[email protected]>
To: [email protected]
Cc:
Sent: Tuesday, October 4, 2011 11:19 AM
Subject: Re:
On 10/04/2011 05:51 PM, Ted Gruenloh wrote:
> The django online documentation mentions that the SQL equivalent for
> __icontains is something like:
>
> SELECT ... WHERE headline ILIKE '%Lennon%';
> However, for postgresql - one of the dbs that actually supports ILIKE - I
> noticed __icontains was actually performing something similar to:
> SELECT ... WHERE LOWER(headline) LIKE LOWER('%Lennon%');
>
> The ILIKE is obviously much faster [...]
https://code.djangoproject.com/ticket/3575
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.