Subject | RE: [firebird-support] Re: best query to find the first row ordering by a column, with a constraint |
---|---|
Author | Svein Erling Tysvær |
Post date | 2010-03-02T08:47:24Z |
You may not need to, we just don't know whether you have 4 or 4 million different source_ids. If you have lots of source_ids, then an index for this field would be preferable. Having a combined index on several fields may be slightly quicker than individual indexes on each field, but that's only required if you want to squeeze the last few percent of performance out of your query at the cost of possibly having lots of additional indexes in your database (assuming you need similar indexes for other fields). I tend to avoid combined indexes unless single indexes would have lousy selectivity (lots of duplicates), but that's just because I prefer simple databases and generally settle for 'good enough' rather than 'optimal for this particular situation'. Generally, I do not want to create a new index for most queries I design! I can appreciate the use of combined indexes in certain situations, it is just that in my situation I normally find them to be more of a hassle.
You'll notice a huge improvement in performance just by creating a DESCending index on your DATE field.
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of korkless
Sent: 2. mars 2010 09:26
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: best query to find the first row ordering by a column, with a constraint
thanks both (you and ann) for the replies.
but why i need to order also for the source_id?
(sorry if the question is stupid but i'm new to the db world :) )
You'll notice a huge improvement in performance just by creating a DESCending index on your DATE field.
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of korkless
Sent: 2. mars 2010 09:26
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: best query to find the first row ordering by a column, with a constraint
thanks both (you and ann) for the replies.
but why i need to order also for the source_id?
(sorry if the question is stupid but i'm new to the db world :) )