[ 
https://issues.apache.org/jira/browse/DERBY-6942?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16079341#comment-16079341
 ] 

Bryan Pendleton commented on DERBY-6942:
----------------------------------------

This seems like a reasonable approach to me.

As I'm understanding your idea, it might be something like this (I don't have 
the syntax quite right, just trying to understand your idea):

{code:java}
float estimateProportion( Object queryStart, Object queryEnd, Object tableMin, 
Object tableMax )
{code}
or
{code:java}
float estimateProportion( <T> queryStart, <T> queryEnd, <T> tableMin, <T> 
tableMax )
{code}
as a generic method.

where queryStart and queryEnd come from the WHERE clause of my SELECT, and 
tableMin and tableMax come from the statistics.

and the estimateProportion method would return a value between 0 and 1.


So, for example,

{code:java}
SELECT * FROM Flights WHERE flight_id BETWEEN 'AA1111' AND 'AA1112'
{code}

or

{code:java}
SELECT * FROM FlightAvailability WHERE business_seats_taken BETWEEN 0 AND 10
{code}

In the above examples, queryStart/queryEnd would be  'AA1111'/'AA1112' in the 
first case, and 0/10 in the second.

In the case of an integer, it might be implemented, more or less, as:
{code:java}
    return (float)(queryEnd-queryStart)/(float)(tableMax-tableMin);
{code}
but as you say, data types like string or date would have more complex analysis 
to do.

It seems like this might fit pretty well into the DataValueDescriptor group of 
Java classes in Derby.

Have a look at the code in 
java/engine/org/apache/derby/iapi/types/*DataValue*.java, and see what you 
think?


> Utilise additional statistics for selectivity estimates.
> --------------------------------------------------------
>
>                 Key: DERBY-6942
>                 URL: https://issues.apache.org/jira/browse/DERBY-6942
>             Project: Derby
>          Issue Type: Sub-task
>          Components: SQL
>            Reporter: Harshvardhan Gupta
>            Assignee: Harshvardhan Gupta
>            Priority: Minor
>         Attachments: DERBY-6942.diff, z12.txt, z13.txt
>
>




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to