PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
21.24k stars 1.26k forks source link

perf: Resolve field alias types in nullable checks #25247

Closed tkaemming closed 1 week ago

tkaemming commented 1 week ago

Problem

ifNull wrapping of comparisons involving field aliases to non-nullable field types prevents the ClickHouse analyzer from being able to use the comparison expression during index selection. This causes us to read much more data than is necessary for some queries.

See also: https://posthog.slack.com/archives/C076E99B152/p1727293461665069?thread_ts=1727254857.130799&cid=C076E99B152

Changes

Resolve field alias expressions to their actual type when determining whether or not the field is nullable.

Does this work well for both Cloud and self-hosted?

Yes.

How did you test this code?

Updated snapshots, updated tests.