Subject | RE: [firebird-support] Using NATURAL plan instead of index - why? |
---|---|
Author | Maya Opperman |
Post date | 2012-10-31T09:17:08Z |
> Running SET STATISTICS on this particular indexNo Change: 0.0000049277592
> Query RDB$INDICES.RDB$STATISTICS for this index
>Also you can generate a histogram of the used values/permutation with:Neat trick, but not sure what I should be looking at exactly. Returns about 200 000 records.
>select
> sourcetype
> , transactiontype
> , refno
> , count(*)
>from
> stk_stocktransaction
>group by
> sourcetype
> , transactiontype
> , refno
>This gives you the value distribution across the entire index.
The SQL I am testing with, returns no records.
Interestingly though, this histogram query DOES use my index ;-)
Which gave me an idea:
I changed my original query to:
select t.SalesOrderNo from stk_stocktransaction t
where (t.SourceType = 34)
and (t.TransactionType = 'EXTCST')
and (t.RefNo = 'I00001')
order by t.SourceType, t.TransactionType, t.RefNo
This DOES use the index.
BUT, it's on average 50% SLOWER than the NATURAL plan the Firebird chose to use.
<scratching head>