Skip to content

Variable resolution and dynamic lookup evaluation incorrect or performing too many lookups #410

@alancai98

Description

@alancai98

Variable resolution currently checks the local bindings and then searches the global context for each lookup:

let value = Bindings::get(bindings, &self.name).or_else(|| ctx.bindings().get(&self.name));

There is currently no way to perform the global lookup first and then the local binding lookup that is required when a variable or path in the FROM source is unqualified as specified in section 10 of the spec. This is apparent in a test case such as:

-- assuming a global table is defined as `foo`
SELECT a FROM foo, foo AS t2

The LHS of the cross join will be correct in pulling foo from the globals since the local bindings are empty. This will put foo in the local bindings. However the RHS of the cross join should check globals first (from section 10 of the spec) but will check the locals bindings first due to the current variable reference implementation.


Another consequence of the current modeling of variable references is that dynamic lookup will check the global context for every local variable lookup. For instance if we have some dynamic lookup of [path(local(a)), path(local(b)), path(local(c)), varref(global(d))], the actual lookup will do something like:

  1. local lookup of a; if nothing, then global lookup of a
  2. if nothing, local lookup of b; if nothing, then global lookup of b
  3. if nothing, local lookup of c; if nothing, then global lookup of c
  4. if nothing, global lookup of d
  5. else Missing

when it should be something like:

  1. local lookup of a
  2. if nothing, local lookup of b
  3. if nothing, local lookup of c
  4. if nothing, global lookup of d
  5. else Missing

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions