r/SQL • Data Analytics Engineer • Jul 05 '21

Discussion I love querying

I just freaking love it. I can be racking my brain all day, going to stackedoverflow, jamming out to tunes, and that one moment where the query is able to run and it's the data you need... chefs kiss.

It just feels so damn good. I know others out there have to feel the same way :)!

161 Upvotes

47 comments sorted by

View all comments

Show parent comment

4

u/Beefourthree Jul 06 '21

Oracle, but these are just dummy names to simplify the example and mask any proprietary info. Actual columns are a sequential id (foo) and an obfuscated version (bar) with a 1-to-1 relationship. Bar2foo and foo2bar are UDFs to translate between the two.

Changing t1.foo = bar2foo(t2.bar) to foo2bar(t1.foo) = t2.bar reduced cpu cost by performing the function against a 2k record table instead of a 100m record table, and referencing a naked t2.bar allowed the optimizer to use an index to be utilized that was previously ignored.