Swap the implementation of [maybe_]get_path_rvar
Currently, `maybe_get_path_rvar()` is implemented in terms of
`get_path_rvar()`, which is inefficient because an expensive exception
instance is created and thrown.  Fix this by flipping the roles and
implementing `get_path_rvar()` in terms of `maybe_get_path_rvar()`.
@@ -655,10 +655,7 @@ def put_path_rvar_if_not_exists(
def get_path_rvar(
stmt: pgast.Query, path_id: irast.PathId, *,
aspect: str, env: context.Environment) -> pgast.PathRangeVar:
- rvar = stmt.path_rvar_map.get((path_id, aspect))
- if rvar is None:
- if aspect == 'identity':
- rvar = stmt.path_rvar_map.get((path_id, 'value'))
+ rvar = maybe_get_path_rvar(stmt, path_id, aspect=aspect, env=env)
if rvar is None:
raise LookupError(
f'there is no range var for {path_id} {aspect} in {stmt}')
@@ -668,10 +665,10 @@ def get_path_rvar(
def maybe_get_path_rvar(
stmt: pgast.Query, path_id: irast.PathId, *, aspect: str,
env: context.Environment) -> Optional[pgast.PathRangeVar]:
- try:
- return get_path_rvar(stmt, path_id, aspect=aspect, env=env)
- except LookupError:
- return None
+ rvar = stmt.path_rvar_map.get((path_id, aspect))
+ if rvar is None and aspect == 'identity':
+ rvar = stmt.path_rvar_map.get((path_id, 'value'))
+ return rvar
def list_path_aspects(
