1515 *
1616 *
1717 * IDENTIFICATION
18- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.178 2005/04/25 01:30:14 tgl Exp $
18+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.179 2005/06/01 17:05:11 tgl Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
@@ -163,7 +163,7 @@ static void examine_variable(Query *root, Node *node, int varRelid,
163163static double get_variable_numdistinct (VariableStatData * vardata );
164164static bool get_variable_maximum (Query * root ,VariableStatData * vardata ,
165165Oid sortop ,Datum * max );
166- static Selectivity prefix_selectivity (Query * root ,VariableStatData * vardata ,
166+ static Selectivity prefix_selectivity (Query * root ,Node * variable ,
167167Oid opclass ,Const * prefix );
168168static Selectivity pattern_selectivity (Const * patt ,Pattern_Type ptype );
169169static Datum string_to_datum (const char * str ,Oid datatype );
@@ -812,6 +812,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
812812List * args = (List * )PG_GETARG_POINTER (2 );
813813int varRelid = PG_GETARG_INT32 (3 );
814814VariableStatData vardata ;
815+ Node * variable ;
815816Node * other ;
816817bool varonleft ;
817818Datum constval ;
@@ -836,6 +837,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
836837ReleaseVariableStats (vardata );
837838return DEFAULT_MATCH_SEL ;
838839}
840+ variable = (Node * )linitial (args );
839841
840842/*
841843 * If the constant is NULL, assume operator is strict and return zero,
@@ -939,7 +941,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
939941
940942if (eqopr == InvalidOid )
941943elog (ERROR ,"no = operator for opclass %u" ,opclass );
942- eqargs = list_make2 (vardata . var ,prefix );
944+ eqargs = list_make2 (variable ,prefix );
943945result = DatumGetFloat8 (DirectFunctionCall4 (eqsel ,
944946PointerGetDatum (root ),
945947ObjectIdGetDatum (eqopr ),
@@ -958,7 +960,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
958960Selectivity selec ;
959961
960962if (pstatus == Pattern_Prefix_Partial )
961- prefixsel = prefix_selectivity (root ,& vardata ,opclass ,prefix );
963+ prefixsel = prefix_selectivity (root ,variable ,opclass ,prefix );
962964else
963965prefixsel = 1.0 ;
964966restsel = pattern_selectivity (rest ,ptype );
@@ -3694,7 +3696,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype,
36943696 * more useful to use the upper-bound code than not.
36953697 */
36963698static Selectivity
3697- prefix_selectivity (Query * root ,VariableStatData * vardata ,
3699+ prefix_selectivity (Query * root ,Node * variable ,
36983700Oid opclass ,Const * prefixcon )
36993701{
37003702Selectivity prefixsel ;
@@ -3706,7 +3708,7 @@ prefix_selectivity(Query *root, VariableStatData *vardata,
37063708BTGreaterEqualStrategyNumber );
37073709if (cmpopr == InvalidOid )
37083710elog (ERROR ,"no >= operator for opclass %u" ,opclass );
3709- cmpargs = list_make2 (vardata -> var ,prefixcon );
3711+ cmpargs = list_make2 (variable ,prefixcon );
37103712/* Assume scalargtsel is appropriate for all supported types */
37113713prefixsel = DatumGetFloat8 (DirectFunctionCall4 (scalargtsel ,
37123714PointerGetDatum (root ),
@@ -3728,7 +3730,7 @@ prefix_selectivity(Query *root, VariableStatData *vardata,
37283730BTLessStrategyNumber );
37293731if (cmpopr == InvalidOid )
37303732elog (ERROR ,"no < operator for opclass %u" ,opclass );
3731- cmpargs = list_make2 (vardata -> var ,greaterstrcon );
3733+ cmpargs = list_make2 (variable ,greaterstrcon );
37323734/* Assume scalarltsel is appropriate for all supported types */
37333735topsel = DatumGetFloat8 (DirectFunctionCall4 (scalarltsel ,
37343736PointerGetDatum (root ),
@@ -3743,7 +3745,7 @@ prefix_selectivity(Query *root, VariableStatData *vardata,
37433745prefixsel = topsel + prefixsel - 1.0 ;
37443746
37453747/* Adjust for double-exclusion of NULLs */
3746- prefixsel += nulltestsel (root ,IS_NULL ,vardata -> var ,0 );
3748+ prefixsel += nulltestsel (root ,IS_NULL ,variable ,0 );
37473749
37483750/*
37493751 * A zero or slightly negative prefixsel should be converted into