I'll bet that if you benchmark, 99% of the runtime is spent in the database. It almost always is.
As for why it's slow ... the reasons are very simple and boil down to "programmers don't understand databases". I assume you're using MySQL, but the points are applicable to most other RDBMSes.
- I'll bet you don't have an index on the aggregated_area column.
- I'll bet that column is TEXT, meaning that even if you are indexing it, you're indexing it improperly. You have to index the first N characters (up to 255 for MySQL).
- If you're using LIKE to find substrings, then you'd be better off breaking that column out into a separate table and indexing that table.
- If they do have % or _ signs and you have them as the first character, then indexes are completely ignored. (They have to be, if you think about it.)
The bottom line is LIKE has extremely poor performance characteristics and should be avoided whenever possible. If you're using LIKE, you had better have exhausted all other possibilities, like normalization.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.