RE: UDF in WHERE clause causes an odd execution plan

"Becker, Holger" <[email protected]> Fri, 18 May 2007 11:34:45 +0200
Newsgroups gmane.comp.db.maxdb
Message-ID <[email protected]>
Vlad Arkhipov wrote:

> CREATE TABLE GIS2.SERVICES (
>     ID INTEGER NOT NULL DEFAULT SERIAL(1) PRIMARY KEY,
>     CODE VARCHAR(10) NOT NULL UNIQUE
> )
> 
> CREATE TABLE GIS2.SERVICE_DATA (
>     ID INTEGER NOT NULL DEFAULT SERIAL(1) PRIMARY KEY
> )
> 
> CREATE FUNCTION GIS2.GETSERVICEID (
>     RESID CHAR(10))
> RETURNS INTEGER
> AS
>     VAR ID INTEGER;
> 
>     TRY
>         SELECT ID INTO :ID FROM GIS2.SERVICES WHERE CODE = :RESID;
>     CATCH
>         IF $rc <> 100 THEN STOP($rc, 'unexpected error')
>         ELSE RETURN NULL;
> 
>     RETURN ID;
> 
> EXPLAIN
> SELECT ID
> FROM GIS2.SERVICE_DATA
> WHERE ID = 1
> 
>  OWNER     TABLENAME      COLUMN_OR_INDEX     
> STRATEGY                                PAGECOUNT   
>  --------  -------------  ------------------  
> --------------------------------------  ------------
>  GIS2      SERVICE_DATA                       EQUAL CONDITION FOR 
> KEY                        542  
>                           ID                       (USED KEY 
> COLUMN)                              
>            JDBC_CURSOR_4                         RESULT IS 
> NOT COPIED , 
> COSTVALUE IS           1  
> 
> EXPLAIN
> SELECT ID
> FROM GIS2.SERVICE_DATA
> WHERE ID = GIS2.GETSERVICEID('12345')
> 
> OWNER     TABLENAME      COLUMN_OR_INDEX     
> STRATEGY                                PAGECOUNT   
>  --------  -------------  ------------------  
> --------------------------------------  ------------
>  GIS2      SERVICE_DATA                       TABLE 
> SCAN                                      35  
>            JDBC_CURSOR_2                         RESULT IS 
> NOT COPIED , 
> COSTVALUE IS          35  
> 
> Tested on MaxDB 7.6.00.16 - 016-123-109-428.
 

Hi,

the optimizer doesn't support such conditions with user defined functions by now.
We have to discuss if we will support it in the future.
If your example comes from a real application and is not only a simplified example
you could use a sub select instead.
Example:

EXPLAIN
SELECT ID
FROM GIS2.SERVICE_DATA
WHERE ID = (SELECT ID FROM GIS2.SERVICES WHERE CODE = '12345')

Kind regards
Holger


Holger Becker
MaxDB&liveCache
SAP AG
www.sap.com
Sitz der Gesellschaft/Registered Office: Walldorf, Germany
Vorstand/SAP Executive Board: Henning Kagermann (Sprecher/CEO),  Léo Apotheker, Werner Brandt, Claus Heinrich, Gerhard Oswald, Peter Zencke
Vorsitzender des Aufsichtsrats/Chairperson of the SAP Supervisory Board: Hasso Plattner 
Registergericht/Commercial Register Mannheim No HRB 350269

Diese E-Mail kann Betriebs- oder Geschäftsgeheimnisse oder sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtümlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfältigung oder Weitergabe der E-Mail ausdrücklich untersagt.
Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen Dank.

This e-mail may contain trade secrets or privileged, undisclosed, or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying, or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation. 

 

-- 
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[email protected]