db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel John Debrunner (JIRA)" <derby-...@db.apache.org>
Subject [jira] Commented: (DERBY-742) Use a single result BooleanDataValue for a boolean expression in class generation
Date Mon, 05 Dec 2005 20:38:08 GMT
    [ http://issues.apache.org/jira/browse/DERBY-742?page=comments#action_12359342 ] 

Daniel John Debrunner commented on DERBY-742:
---------------------------------------------

After looking at this in more detail, it's actually the short circuit logic that is causing
all the BooleanDataValue fields. The generated code for A AND B is roughly

BooleanDataValue e67; // a generated field in the class

if (A.equals(false)) // false here and in the getBoolean is the 'short circuit constant'
{
    result = e67 = getDataValueFactory().getBoolean(false, e67);
}
else
{
    result = A.and(B);
}

No result holder is used for the method BooleanDataValue.and or BooleanDataValue.or because
they return an immutable BooleanDataValue.

The same code is used to execute OR, in that case the short circuit constant is 'true' rather
than 'false' in this case.

Replacing the use of a holder in the short circuit code with an immuntable BooleanDataValue
would reduce the amount of code generated for this query.



> Use a single result BooleanDataValue for a boolean expression in class generation
> ---------------------------------------------------------------------------------
>
>          Key: DERBY-742
>          URL: http://issues.apache.org/jira/browse/DERBY-742
>      Project: Derby
>         Type: Sub-task
>   Components: SQL
>     Reporter: Daniel John Debrunner
>     Assignee: Daniel John Debrunner
>     Priority: Minor

>
> BinaryLogicalOperatorNode.generateExpression() creates a BooleanDataValue for the result
of the expression, this is to avoid object generation during runtime.
> The code is logically like (ignoring the short circuit logic) for the SQL <left>
AND <right>
> BooleanDataValue   e34; // instance field for the result
>  e34 = <left>.and( <right>,  e34);
> The and method on BooleanDataValue will create a new BooleanDataValue if the passed in
e34 is null, otherwise re-use it.
> On the first execution e34 will be null, and thus the 'and' method will create an object
and it will get stored in e34.
> [ Ignore for the moment the inefficiency of setting e34 everytime to the same value on
every subsequent execution. ]
> [ This approach is standard practice in the generated code and elsewhere and ensures
that  object allocation within a Derby ]
> [ statement execution is a fixed cost, and not linear with the number of rows scanned.
]
> This issue is about what happens when multiple boolean expressions get combined, as in
the query in DERBY-732. For each AND/OR
> a new BooleanDataValue field is created to hold the result of the intrermediate step,
e.g. for the SQL ( <A> AND <B> ) AND <C>
> BooleanDataValue   e34; // instance field for the result of A and B
> BooleanDataValue   e35; // instance field for the final result
>  e34 = <A>.and( <B>,  e34);
>  e35 = <e34>.and(<C>, e35);
> But since this is a single expression, of the same type up and down the tree, why not
 have a single BooleanDataValue for the result
> BooleanDataValue   e36; // instance field for the final result
>  e36 = <A>.and( <B>,  e36);
>  e36 = <e36>.and(<C>, e36);
> or
> e36 = new BooleanDataValue(); // through data value factory
> <A>.and( <B>,  e36);
> <e36>.and(<C>, e36);
> The query for DERBY-732 has over 500 BooleanDataValue   fields, which I think are all
intermediate result holders.
> Would need to document that the and and or methods return the result passed in if it
is not null, which I think is the case for
> all DataValueDescriptor methods that take a result parameter.
> [ [ 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message