code: def _iter_by(
      all_by: Sequence[GroupingKey],
  ) -> Iterator[Sequence[GroupingKey]]:
      """
      Iterate over all possible subsets of grouping keys, sorted by cost.
      """
      todo: List[Tuple[float, int, List[GroupingKey]]] = [(0.0, 0, [])]
      while todo:
          _, prev_begin, prev_by = heapq.heappop(todo)
          yield prev_by
          for i, next_key in enumerate(all_by[prev_begin:]):
              next_begin = prev_begin + i + 1
              next_by = prev_by + [next_key]
              next_cost = sum(k.key_cost for k in next_by)
              heapq.heappush(todo, (next_cost, next_begin, next_by))
  
imports: import heapq
  from dataclasses import dataclass
  from enum import Enum
  from typing import Any, Collection, Iterator, List, Sequence, Tuple, Type
  import pandas
  from benchmark.metadata import BenchmarkMetadata
  from benchmark.plotter_api import Plotter
label_desc: Use image node_id 4 for calling a global function with example usage: _iter_by(all_by) without return types