MaterializeInc / materialize

The data warehouse for operational workloads.
https://materialize.com
Other
5.68k stars 458 forks source link

Boolean comparison breaks autorouting #26738

Open sjwiesman opened 3 months ago

sjwiesman commented 3 months ago

What version of Materialize are you using?

v0.96.2

What is the issue?

For whatever reason, this autoroutes to mz_introspection:

SELECT mz_is_superuser();

But this does not.

SELECT mz_is_superuser() IS FALSE;

I didn't dig into this, and is likely not urgent, but documenting for later.

benesch commented 3 months ago

This is working as designed, I'm afraid. I agree it's somewhat hard to explain, but autorouting only kicks in for "cheap" queries, and our definition of "cheap" is "100% guaranteed to be executable without involving the compute layer". mz_is_superuser() is unmaterializable, and so we can execute entirely it in the adapter, but SELECT mz_is_superuser() IS FALSE involves calling the IS FALSE operator, which lives in compute, and therefore we aren't certain that it is "cheap." (Obviously in this case it's a bit silly, as IS FALSE is obviously cheap, but with something like generate_series(1, 1000) it becomes clearer. Whether that's cheap our not depends on how large the series is, and that threshold moves around over time, and we don't want autorouting to depend on what the optimizer's current threshold for "cheap" is.)

https://github.com/MaterializeInc/materialize/blob/603721eea933365dfd62a9791673db039430c8a8/src/sql/src/plan/expr.rs#L1883-L1891