* pathkeys_count_contained_in * Same as pathkeys_contained_in, but also sets length of longest * common prefix of keys1 and keys2. */
| 669 | * common prefix of keys1 and keys2. |
| 670 | */ |
| 671 | bool |
| 672 | pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common) |
| 673 | { |
| 674 | int n = 0; |
| 675 | ListCell *key1, |
| 676 | *key2; |
| 677 | |
| 678 | /* |
| 679 | * See if we can avoiding looping through both lists. This optimization |
| 680 | * gains us several percent in planning time in a worst-case test. |
| 681 | */ |
| 682 | if (keys1 == keys2) |
| 683 | { |
| 684 | *n_common = list_length(keys1); |
| 685 | return true; |
| 686 | } |
| 687 | else if (keys1 == NIL) |
| 688 | { |
| 689 | *n_common = 0; |
| 690 | return true; |
| 691 | } |
| 692 | else if (keys2 == NIL) |
| 693 | { |
| 694 | *n_common = 0; |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * If both lists are non-empty, iterate through both to find out how many |
| 700 | * items are shared. |
| 701 | */ |
| 702 | forboth(key1, keys1, key2, keys2) |
| 703 | { |
| 704 | PathKey *pathkey1 = (PathKey *) lfirst(key1); |
| 705 | PathKey *pathkey2 = (PathKey *) lfirst(key2); |
| 706 | |
| 707 | if (pathkey1 != pathkey2) |
| 708 | { |
| 709 | *n_common = n; |
| 710 | return false; |
| 711 | } |
| 712 | n++; |
| 713 | } |
| 714 | |
| 715 | /* If we ended with a null value, then we've processed the whole list. */ |
| 716 | *n_common = n; |
| 717 | return (key1 == NULL); |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * get_cheapest_path_for_pathkeys |
no test coverage detected