Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1bd3a8f

Browse files
committed
Repair bug noted by Paul Caskey: neqsel() has been generating a bogus
result, in fact nearly the opposite of what it should, because itwas passing the not-equal operator to eqsel() which would use it tocompare the value against the most common value in the column, andof course obtain the wrong result therefrom. Must pass the equalityoperator to eqsel() instead. Fortunately that's easy to get fromthe oprnegate link.
1 parent463f1f5 commit1bd3a8f

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

‎src/backend/utils/adt/selfuncs.c

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.76 2000/07/29 03:26:42 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.77 2000/08/03 00:58:22 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -252,9 +252,33 @@ eqsel(PG_FUNCTION_ARGS)
252252
Datum
253253
neqsel(PG_FUNCTION_ARGS)
254254
{
255+
Oidopid=PG_GETARG_OID(0);
256+
Oidrelid=PG_GETARG_OID(1);
257+
AttrNumberattno=PG_GETARG_INT16(2);
258+
Datumvalue=PG_GETARG_DATUM(3);
259+
int32flag=PG_GETARG_INT32(4);
260+
Oideqopid;
255261
float8result;
256262

257-
result=DatumGetFloat8(eqsel(fcinfo));
263+
/*
264+
* We want 1 - eqsel() where the equality operator is the one associated
265+
* with this != operator, that is, its negator.
266+
*/
267+
eqopid=get_negator(opid);
268+
if (eqopid)
269+
{
270+
result=DatumGetFloat8(DirectFunctionCall5(eqsel,
271+
ObjectIdGetDatum(eqopid),
272+
ObjectIdGetDatum(relid),
273+
Int16GetDatum(attno),
274+
value,
275+
Int32GetDatum(flag)));
276+
}
277+
else
278+
{
279+
/* Use default selectivity (should we raise an error instead?) */
280+
result=DEFAULT_EQ_SEL;
281+
}
258282
result=1.0-result;
259283
PG_RETURN_FLOAT8(result);
260284
}
@@ -392,15 +416,39 @@ scalarltsel(PG_FUNCTION_ARGS)
392416
Datum
393417
scalargtsel(PG_FUNCTION_ARGS)
394418
{
419+
Oidopid=PG_GETARG_OID(0);
420+
Oidrelid=PG_GETARG_OID(1);
421+
AttrNumberattno=PG_GETARG_INT16(2);
422+
Datumvalue=PG_GETARG_DATUM(3);
423+
int32flag=PG_GETARG_INT32(4);
424+
Oidltopid;
395425
float8result;
396426

397427
/*
398428
* Compute selectivity of "<", then invert --- but only if we were
399-
* able to produce a non-default estimate.
429+
* able to produce a non-default estimate. Note that we get the
430+
* negator which strictly speaking means we are looking at "<="
431+
* for ">" or "<" for ">=". We assume this won't matter.
400432
*/
401-
result=DatumGetFloat8(scalarltsel(fcinfo));
433+
ltopid=get_negator(opid);
434+
if (ltopid)
435+
{
436+
result=DatumGetFloat8(DirectFunctionCall5(scalarltsel,
437+
ObjectIdGetDatum(ltopid),
438+
ObjectIdGetDatum(relid),
439+
Int16GetDatum(attno),
440+
value,
441+
Int32GetDatum(flag)));
442+
}
443+
else
444+
{
445+
/* Use default selectivity (should we raise an error instead?) */
446+
result=DEFAULT_INEQ_SEL;
447+
}
448+
402449
if (result!=DEFAULT_INEQ_SEL)
403450
result=1.0-result;
451+
404452
PG_RETURN_FLOAT8(result);
405453
}
406454

@@ -567,7 +615,7 @@ nlikesel(PG_FUNCTION_ARGS)
567615
Datum
568616
eqjoinsel(PG_FUNCTION_ARGS)
569617
{
570-
#ifdefNOT_USED
618+
#ifdefNOT_USED/* see neqjoinsel() before removing me! */
571619
Oidopid=PG_GETARG_OID(0);
572620
#endif
573621
Oidrelid1=PG_GETARG_OID(1);
@@ -620,6 +668,11 @@ neqjoinsel(PG_FUNCTION_ARGS)
620668
{
621669
float8result;
622670

671+
/*
672+
* XXX we skip looking up the negator operator here because we know
673+
* eqjoinsel() won't look at it anyway. If eqjoinsel() ever does look,
674+
* this routine will need to look more like neqsel() does.
675+
*/
623676
result=DatumGetFloat8(eqjoinsel(fcinfo));
624677
result=1.0-result;
625678
PG_RETURN_FLOAT8(result);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp