Different Aliases produce different Result for exactly same Query

前端 未结 1 1384
抹茶落季
抹茶落季 2021-01-15 18:14

Below two versions of the same exactly query

Version 1 (uses k as alias in inner SELECT):

SELECT k, w_vol, 
  ROW_NUMBER         


        
相关标签:
1条回答
  • 2021-01-15 18:48

    I don't have a specific explanation for the behavior, but note that both results are still correct: the only difference between the results is that a different order was chosen when sorting several rows that have the same value (1) for the column being sorted (w_vol).

    Generally speaking, BigQuery does not promise any particular ordering when applying ORDER BY to equal values, and that ordering may vary across different executions of the same query for any reason.

    I agree it's interesting that the ordering seems to depend on the alias, but I could see plenty of plausible explanations for why this happens--for example, the engine might iterate through a list of fields that use analytic functions, and changing the alias might change the order in which those analytic functions are evaluated, which in turn changes the ordering of rows with equal values when sorting by one column.

    0 讨论(0)
提交回复
热议问题