LIKE and SIMILAR TO
Hello all,
As we are migrating our ERP application from MySQL to PostgreSQL we have
some difficulties. One of them is use of Like and Similar to operators. We
often use LIKE to search a string from front-end without case sensetivity.
As postgreSQL's LIKE is case sensitive, we tried ILIKE and SIMILAR TO, but
both are slower than LIKE and we must need case insensitivity. How can we
get this by increases speed. All search columns are VARCHAR(100)to
VARCHAR(250). Currently without index.
Thanks,
CPK
Maybe you should give tsearch2 a try and create a GIN index.
Regex searches are sometimes a option.
Robert
c k wrote:
Show quoted text
Hello all,
As we are migrating our ERP application from MySQL to PostgreSQL we
have some difficulties. One of them is use of Like and Similar to
operators. We often use LIKE to search a string from front-end without
case sensetivity. As postgreSQL's LIKE is case sensitive, we tried
ILIKE and SIMILAR TO, but both are slower than LIKE and we must need
case insensitivity. How can we get this by increases speed. All search
columns are VARCHAR(100)to VARCHAR(250). Currently without index.Thanks,
CPK
Hi,
c k wrote:
Hello all,
As we are migrating our ERP application from MySQL to PostgreSQL we have
some difficulties. One of them is use of Like and Similar to operators.
We often use LIKE to search a string from front-end without case
sensetivity. As postgreSQL's LIKE is case sensitive, we tried ILIKE and
SIMILAR TO, but both are slower than LIKE and we must need case
insensitivity. How can we get this by increases speed. All search
columns are VARCHAR(100)to VARCHAR(250). Currently without index.
You could build an index on lower(column) and use lower(column) like ...
this would speed up queries with exact match as well as 'foo%'
e.g. "start with..." match.
Make sure when you create the database cluster (initdb) you
used the currect locale, otherwise lower() (and ilike) probably
do not work as you might expect.
For any more complex searches I'd recommend full text index,
for example tsearch2.
Regards
Tino
Thanks to all,
I will try to use tsearch2 with some other index and then reply.
Regards,
CPK
On Fri, Aug 22, 2008 at 5:01 PM, Tino Wildenhain <tino@wildenhain.de> wrote:
Show quoted text
Hi,
c k wrote:
Hello all,
As we are migrating our ERP application from MySQL to PostgreSQL we have
some difficulties. One of them is use of Like and Similar to operators. We
often use LIKE to search a string from front-end without case sensetivity.
As postgreSQL's LIKE is case sensitive, we tried ILIKE and SIMILAR TO, but
both are slower than LIKE and we must need case insensitivity. How can we
get this by increases speed. All search columns are VARCHAR(100)to
VARCHAR(250). Currently without index.You could build an index on lower(column) and use lower(column) like ...
this would speed up queries with exact match as well as 'foo%'
e.g. "start with..." match.Make sure when you create the database cluster (initdb) you
used the currect locale, otherwise lower() (and ilike) probably
do not work as you might expect.For any more complex searches I'd recommend full text index,
for example tsearch2.Regards
Tino
On Fri, 22 Aug 2008 16:43:47 +0530
"c k" <shreeseva.learning@gmail.com> wrote:
Hello all,
As we are migrating our ERP application from MySQL to PostgreSQL
we have some difficulties. One of them is use of Like and Similar
to operators. We often use LIKE to search a string from front-end
without case sensetivity. As postgreSQL's LIKE is case sensitive,
we tried ILIKE and SIMILAR TO, but both are slower than LIKE and
we must need case insensitivity. How can we get this by increases
speed. All search columns are VARCHAR(100)to VARCHAR(250).
Currently without index.
I was going to suggest to create a functional index
create index on sometable using btree (upper(somecolumn));
select * from sometable where upper(somecolumn)
like '%' || upper(somestring) || '%';
but indexes aren't going to work if you're searching with a prefixed
%.
I was wondering what are the performances of postgresql vs. MySQL in
such case.
Anyway I'd tweak postgresql.conf before complaining it is slower
than MySQL. I've been surprised as well at how postgresql can be
fast.
--
Ivan Sergio Borgonovo
http://www.webthatworks.it