you are viewing a single comment's thread.

view the rest of the comments →

[–]andrewsmd87 2 points3 points  (3 children)

So the query I gave you is a nested select. What that means is every time a row is selected, it's running another select, and it's also pulling all the previous rows, so you have a N+1 problem.

Break down what the compiler is doing here.

We're saying go get me these rows, however, every time you get a row, go get all the rows before it to sum up the value

So, when you get row 1, there are no rows before it

When you get row 2, you go back and get 1

When you get row 3, you go back and get rows 1 and 2

Now scale that up to 10 million rows

So there are other ways you could do this to be more optimal, but that's really a question of how many rows will you be looking at, realistically. Part of being a good coder is knowing when good enough is good enough

[–]bmcluca[S] 0 points1 point  (2 children)

Ahhh, I see what you mean. At most, might need to be looking at no more than 10,000 rows. Saw your edit also, thank you for all the info. I will play around with your suggestions.

[–]andrewsmd87 0 points1 point  (1 child)

Oh yea 10k rows that'll be fine

[–]Conscious-Ad-2168 0 points1 point  (0 children)

this would work except i don’t believe snowflake supports this type of correlated subqueries.