What is a "leaf expression"?

Partition-clause expressions are limited in the following ways:


  • You can specify leaf expressions, functions, and operators in the partition clause expression.
  • All leaf expressions in the partition clause must be either constants or columns of the table.

Source https://my.vertica.com/docs/6.1.x/HTML/index.htm#18125.htm

  • I guess it means "leaf" as when after parsed by the parser and translated into a parse tree – ypercubeᵀᴹ Nov 4 '13 at 15:49
  • If my assumption is correct, this forbids the use of some functions, like CURRENT_TIMESTAMP() and RANDOM() – ypercubeᵀᴹ Nov 4 '13 at 15:57
  • Good question... what a stupid term. – Evan Carroll Jan 18 '18 at 18:48

I'm pretty sure leaf expression means something like "a?b:c". A discrete value from a conditional.

But basically the overall message is saying you need to avoid null values. They can't partition on a null.


Traditionally, leaf and non-leaf refer to nodes in a btree. But, I don't think that has anything to do with the context here.

It's being used in the context of partition statement. The docs for 9.0 are slightly more clear

PARTITION BY expressions can specify leaf expressions, functions, and operators.

In my opinion, leaf expression is a something that can be reduced to a value. The idea of leaf and non-leaf is likely borrowed from procedural programming. Here is an example from a book on Modern X86 Assembly Language Programming: 32-bit, 64-bit, SSE, and AVX

Leaf functions are functions that:

  • Do not call any other functions.
  • Do not modify the contents of the RSP register.
  • Do not allocate any local stack space.
  • Do not modify any of the non-volatile general-purpose or XMM registers.
  • Do not use exception handling.
  • X86-64 assembly language leaf functions are easier to code, but they're only suitable for relatively simple computational tasks.

We can verify that the context of the docs, by taking note of this

It is strongly recommended that you use Vertica's built-in HASH function, which distributes data evenly across the cluster, and facilitates optimal query execution.

In the docs on HASH function, they say,

All leaf expressions must be constants or column references to a column in the CREATE PROJECTION's SELECT list.

So essentially a hash can work over a non-aggregate functions, operators, or leaf expressions (constants or columns). That means the leaf expression is a subset of functions that are pure (lack side-effects) and are simply folded into a literal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.