1

I'm running a case-insensitive search on a table with 7.2 million rows, and I was wondering if there was any way to make this query any faster?

Currently, it takes approx 11.6 seconds to execute, with just one search parameter, and I'm worried that as soon as I add more than one, this query will become massively slow.

SELECT count(*)
FROM "exif_parse"
WHERE (description ~* 'canon')

---Edit---

phpPgAdmin tells me that there is an index on this column as defined below:

desc_idx    CREATE INDEX desc_idx ON exif_parse USING btree (description)

--- Edit 2----

The database contains records in this format:

imaage_id    exif_field    description

And I am running against description as a search, so it contains data from a Tone Curve (0, 0, 32, 22, 64, 56, 128, 128, 192, 196, 255, 255) to Lens (Pentax-F FISH-EYE 1:3.5-4.5 17-28mm) to Make (Canon EOS REBEL XSi)

3

2 Answers 2

4

You should look at using FTS.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you perhaps have a better example of this? I looked through this document, and did a bit of Google research that wasn't really helpful. I'm quite new to PostgreSQL, coming from MySQL.
@Ben Dauphinee: This might help - linuxgazette.net/164/sephton.html ; When in doubt, check the support options - there are mailing lists & IRC: postgresql.org/support
2

You can just create an index like this:

CREATE INDEX idx_exif_parse_description_vpo
    ON exif_parse (lower(description) varchar_pattern_ops)

and the following query will take milliseconds to complete:

SELECT count(*)
FROM "exif_parse"
WHERE (lower(description) LIKE 'canon')

FTS is way overkill for this.

2 Comments

This won't match queries for 'canon 5dkmii'.
Right, to match those you would just append a wildcard character, i.e. LIKE 'canon%'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.