MCPcopy Create free account
hub / github.com/apache/cloudberry / pathkeys_count_contained_in

Function pathkeys_count_contained_in

src/backend/optimizer/path/pathkeys.c:671–718  ·  view source on GitHub ↗

* pathkeys_count_contained_in * Same as pathkeys_contained_in, but also sets length of longest * common prefix of keys1 and keys2. */

Source from the content-addressed store, hash-verified

669 * common prefix of keys1 and keys2.
670 */
671bool
672pathkeys_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

Callers 10

create_window_pathsFunction · 0.85
create_one_window_pathFunction · 0.85
create_ordered_pathsFunction · 0.85
planner.cFile · 0.85
gather_grouping_pathsFunction · 0.85

Calls 2

list_lengthFunction · 0.85
forbothFunction · 0.85

Tested by

no test coverage detected