HN user

ajw0100

165 karma
Posts16
Comments14
View on HN

What if the limits on the lateral subqueries were 2 instead of 1, and they were doing select * instead on select sum() in the outer query? How would you recreate that with correlated SCALAR subqueries? There's no such thing as non-scalar correlated subqueries is there?

Looking at this a little further, the outer nested loop could cause issues in the left join vs. left join lateral version, depending on how many use_demo events there are in the week following the user's first view_homepage event. I added another query that uses CTEs which allows for intermediate aggregation which should make the size of the nested loops similar between both versions. However, I wouldn't be surprised if the CTEs take more memory than the lateral joins because CTEs are basically temp tables that only last for the duration of the query. Lateral may indeed be the best option but ideally I would populate this table with real data, gather statistics, and then run explain analyze on each query.

Yet they say their revenue is only "well into the 6-figures"? How is this possible? If only 5000 of those customers are paying the lowest per rep per month rate of $25 than that amounts to $1.5 million over the course of a year. And I have to believe a lot of their customers have more than one rep. Churn couldn't be making that much of a difference could it? Knowing Dan from his writing I'm sure he's going out of his way to please customers.

Not trying to call them out. I really like Dan and have learned a lot from his writing. I hope they do actually have that many customers paying $25-99 per rep per month. Just wondering how it adds up?

How I write SQL 13 years ago

This is a breeze. Don't make me paste some of the wacky SQL I've seen generated from Oracle's BI tools when they are being abused.

How I write SQL 13 years ago

Python is the same way - it lets you have trailing commas for lists, tuples, and dictionaries.

How I write SQL 13 years ago

Along the same lines it makes it easier to comment out items when debugging. Especially if you add in tricks like SELECT 0.

For example multiple lines in this query would cause an error:

    SELECT a.field1,
      a.field2,
    --  b.field1,
    --  b.field2,
      c.field1,
    --  b.field3
    FROM a,
    --  b,
      c
    WHERE --a.field1 = b.field1
      AND a.field2 = c.field1
This query would not cause an error (Note that DUAL is a dummy table in Oracle that contains 1 column and row):
    SELECT 0
    , a.field1
    , a.field2
    --, b.field1
    --, b.field2
    , c.field1
    --, b.field3
    FROM dual 
    , a
    --, b
    , c
    WHERE 0=0
    --  AND a.field1 = b.field1
      AND a.field2 = c.field1
It does add a 0 column to the result set but that can be dealt with or removed after development.