Subject | RE: [firebird-support] Re: How to mix ascending and descending fields in one index |
---|---|
Author | Svein Erling Tysvær |
Post date | 2009-10-09T09:21:45Z |
Even if Martijns suggestion was wrong, maybe it could be part of a good solution?
with C_INT_ALL(C_INT)
as (select first 10 C_INT
from CSV_DATA_TEST2
order by C_INT desc),
C_INT_UNIQUE(C_INT)
as (select distinct C_INT
from C_INT_ALL)
select first 10 T1.*
from CSV_DATA_TEST2 T1
join C_INT_UNIQUE T2 on T1.C_INT = T2.C_INT
order by T1.c_float asc
This will, of course, not work on Firebird 1.5 or older versions. I assume the speed will vary depending on the selectivity of C_INT and C_FLOAT.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Martijn Tonies
Sent: 9. oktober 2009 10:47
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Re: How to mix ascending and descending fields in one index
Hmm, good thinking... Not the correct solution as the OP did state
that column "A" could have the same values...
With regards,
Martijn Tonies
with C_INT_ALL(C_INT)
as (select first 10 C_INT
from CSV_DATA_TEST2
order by C_INT desc),
C_INT_UNIQUE(C_INT)
as (select distinct C_INT
from C_INT_ALL)
select first 10 T1.*
from CSV_DATA_TEST2 T1
join C_INT_UNIQUE T2 on T1.C_INT = T2.C_INT
order by T1.c_float asc
This will, of course, not work on Firebird 1.5 or older versions. I assume the speed will vary depending on the selectivity of C_INT and C_FLOAT.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Martijn Tonies
Sent: 9. oktober 2009 10:47
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Re: How to mix ascending and descending fields in one index
Hmm, good thinking... Not the correct solution as the OP did state
that column "A" could have the same values...
With regards,
Martijn Tonies
>> The derived table select takes milliseconds.
> ...
>> select
>> *
>> from
>> ( select first 10 * from
>> CSV_DATA_TEST_2
>> order by C_INT desc) as first_10
>> order by first_10.c_float asc
>
> But is that really the same thing?
>
> select first 10 * from
> CSV_DATA_TEST_2
> order by C_INT desc
>
> does not (necessarily) return the same 10 rows as
>
> select first 10 * from
> CSV_DATA_TEST_2
> order by C_INT desc, c_float asc
>
>
> If there were 50 rows all with C_INT = 1
> then your statement will return a random(ish)
> selection of 10 of them.
> If there was some known limiter value for C_INT
> then a WHERE clause could be used... but I suspect
> that would work without derived tables too.