| 533 | | /* CS186 HW2: fill me in! */ |
| 534 | | return get_float8_infinity(); |
| | 533 | int keySize = scan->numberOfKeys; |
| | 534 | ScanKey key = scan->keyData; |
| | 535 | Relation r = scan->indexRelation; |
| | 536 | GISTScanOpaque so; |
| | 537 | Page p; |
| | 538 | GISTSTATE *giststate; |
| | 539 | double retval = 0; |
| | 540 | |
| | 541 | so = (GISTScanOpaque) scan->opaque; |
| | 542 | giststate = so->giststate; |
| | 543 | p = BufferGetPage(so->curbuf); |
| | 544 | |
| | 545 | while (keySize > 0) |
| | 546 | { |
| | 547 | Datum datum; |
| | 548 | bool isNull; |
| | 549 | Datum test; |
| | 550 | GISTENTRY de; |
| | 551 | |
| | 552 | datum = index_getattr(tuple, |
| | 553 | key->sk_attno, |
| | 554 | giststate->tupdesc, |
| | 555 | &isNull); |
| | 556 | |
| | 557 | if (key->sk_flags & SK_ISNULL) |
| | 558 | { |
| | 559 | /* |
| | 560 | * is the compared-to datum NULL? on non-leaf page it's possible |
| | 561 | * to have nulls in childs :( |
| | 562 | */ |
| | 563 | |
| | 564 | if (isNull || !GistPageIsLeaf(p)) |
| | 565 | return get_float8_infinity(); |
| | 566 | return 0; |
| | 567 | } |
| | 568 | else if (isNull) |
| | 569 | return 0; |
| | 570 | |
| | 571 | gistdentryinit(giststate, key->sk_attno - 1, &de, |
| | 572 | datum, r, p, offset, |
| | 573 | FALSE, isNull); |
| | 574 | |
| | 575 | /* |
| | 576 | * Call the Distance function to evaluate the test. The arguments |
| | 577 | * are the index datum (as a GISTENTRY*), and the comparison datum. |
| | 578 | */ |
| | 579 | test = FunctionCall2(&giststate->distanceFn[key->sk_attno - 1], |
| | 580 | PointerGetDatum(&de), |
| | 581 | key->sk_argument); |
| | 582 | |
| | 583 | retval += DatumGetFloat8(test); |
| | 584 | |
| | 585 | keySize--; |
| | 586 | key++; |
| | 587 | } |
| | 588 | |
| | 589 | return retval; |