Ilike sql query5/3/2023 As you can see below, the query is just as slow. You might think that indexing this column with a standard btree index would help this search - it doesn’t. 520 rows = 0 loops = 1 ) Filter : (( username ):: text ~~* '%foo%' :: text ) Rows Removed by Filter : 1000000 Planning time : 0. 00 rows = 96 width = 0 ) ( actual time = 737. 523 rows = 1 loops = 1 ) -> Seq Scan on users ( cost = 0. 25 rows = 1 width = 0 ) ( actual time = 737. $ > EXPLAIN ANALYSE SELECT COUNT ( * ) FROM users WHERE username ILIKE '%foo%' QUERY PLAN - Aggregate ( cost = 21927. I’ve got a very simple users database table populated with 1 million rows. I'm pretty sure Postgres has already solved most of my problems, I just haven't made it to that part of the documentation yet. Indexing columns for LIKE queries was perfect example of this. Whenever I need something from it, it’s usually already there, I just cant always find how to do it. The more I work with PostgreSQL the more it impresses me. Quite often, structuring and indexing the database correctly can keep your queries nice and fast. However, we don’t always need such substantial dependencies in an app. Tools like Elastic Search or Solr are great at providing quick intelligent searches on large datasets. Users expect search to fast and to be accurate. Search is often an integral part of any web app, but it’s also one of the parts that can cause performance problems. It took me a while to figure out the right way to index columns for LIKE lookups, especially for indexing compound columns. Recently I wanted to add basic text search to an application I as working on.
0 Comments
Leave a Reply. |