Re: Windowing Function Patch Review -> Standard Conformance

Поиск
Список
Период
Сортировка
От Hitoshi Harada
Тема Re: Windowing Function Patch Review -> Standard Conformance
Дата
Msg-id e08cc0400812202110s7c3f2775g2fbd4a16db6dfa93@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Windowing Function Patch Review -> Standard Conformance  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
2008/12/20 Tom Lane <tgl@sss.pgh.pa.us>:
> "Hitoshi Harada" <umi.tanuki@gmail.com> writes:
>> Here's the patch, including latest function default args. Regards,
>
> The comments added to planner.c contain various claims that setrefs.c
> will fix up window function references, but I see no code related to
> that in setrefs.c.  Please explain.
>

The Window node handles only expressions that contain corresponding
window functions. Since more than one Window nodes may be put in a
Plan, the window functions in the upper node are not evaluated in the
lower node but tlist should not forget it exists in the lower. For
examples,

SQL:
SELECT
row_number() OVER (ORDER BY salary) AS r1, row_number() OVER (ORDER BY
depname) AS r2
FROM empsalary;

The final Plan:
-Window (upper) pull r1 (Var) eval r2 (WindowFuncExpr) -Sort by depname   -Window (lower)     eval r1
(WindowFunctionExpr)    r2 as NULL (Const)     -Sort by salary       -Scan empsalary
 

And it is possible for window_tlist() to change upper's r1 to Var but
delegating it to set_upper_references() seems right to do.If we simply
delegate all the nodes to set_upper_reference(), r2 would also be
evaluated in lower node, so we put null const in the lower and put
actual evaluation in the upper.

So window_preprocess and window_tlist do things needed for
set_upper_reference to fix up all the expressions correctly, that's
why no code is added to setrefs.c.

This part is hard to describe in english (or even in my japanese) so
if you are still lost, I'll add more explanation.

Regards,



-- 
Hitoshi Harada


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Hitoshi Harada"
Дата:
Сообщение: Re: Is "Window" really safe as a global typedef name?
Следующее
От: "Fujii Masao"
Дата:
Сообщение: Re: Sync Rep: First Thoughts on Code