|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * 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 $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -252,9 +252,33 @@ eqsel(PG_FUNCTION_ARGS)
|
252 | 252 | Datum
|
253 | 253 | neqsel(PG_FUNCTION_ARGS)
|
254 | 254 | {
|
| 255 | + Oid opid = PG_GETARG_OID(0); |
| 256 | + Oid relid = PG_GETARG_OID(1); |
| 257 | + AttrNumber attno = PG_GETARG_INT16(2); |
| 258 | + Datum value = PG_GETARG_DATUM(3); |
| 259 | + int32 flag = PG_GETARG_INT32(4); |
| 260 | + Oid eqopid; |
255 | 261 | float8 result;
|
256 | 262 |
|
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 | + } |
258 | 282 | result = 1.0 - result;
|
259 | 283 | PG_RETURN_FLOAT8(result);
|
260 | 284 | }
|
@@ -392,15 +416,39 @@ scalarltsel(PG_FUNCTION_ARGS)
|
392 | 416 | Datum
|
393 | 417 | scalargtsel(PG_FUNCTION_ARGS)
|
394 | 418 | {
|
| 419 | + Oid opid = PG_GETARG_OID(0); |
| 420 | + Oid relid = PG_GETARG_OID(1); |
| 421 | + AttrNumber attno = PG_GETARG_INT16(2); |
| 422 | + Datum value = PG_GETARG_DATUM(3); |
| 423 | + int32 flag = PG_GETARG_INT32(4); |
| 424 | + Oid ltopid; |
395 | 425 | float8 result;
|
396 | 426 |
|
397 | 427 | /*
|
398 | 428 | * 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. |
400 | 432 | */
|
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 | + |
402 | 449 | if (result != DEFAULT_INEQ_SEL)
|
403 | 450 | result = 1.0 - result;
|
| 451 | + |
404 | 452 | PG_RETURN_FLOAT8(result);
|
405 | 453 | }
|
406 | 454 |
|
@@ -567,7 +615,7 @@ nlikesel(PG_FUNCTION_ARGS)
|
567 | 615 | Datum
|
568 | 616 | eqjoinsel(PG_FUNCTION_ARGS)
|
569 | 617 | {
|
570 |
| -#ifdef NOT_USED |
| 618 | +#ifdef NOT_USED /* see neqjoinsel() before removing me! */ |
571 | 619 | Oid opid = PG_GETARG_OID(0);
|
572 | 620 | #endif
|
573 | 621 | Oid relid1 = PG_GETARG_OID(1);
|
@@ -620,6 +668,11 @@ neqjoinsel(PG_FUNCTION_ARGS)
|
620 | 668 | {
|
621 | 669 | float8 result;
|
622 | 670 |
|
| 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 | + */ |
623 | 676 | result = DatumGetFloat8(eqjoinsel(fcinfo));
|
624 | 677 | result = 1.0 - result;
|
625 | 678 | PG_RETURN_FLOAT8(result);
|
|
0 commit comments