Zhang Mingli <zmlpostgres@gmail.com> writes:
> When create or refresh a Materialized View, if the view’s query has order by, we may sort and insert the sorted data
intoview.
Indeed.
> And if it’s true, shall we skip the order by clause for Materialized View when executing create/refresh statement?
No. The intent of a materialized view is to execute the query
as presented. If the user doesn't understand the consequences
of that, it's not our job to think we are smarter than they are.
I think this patch should be rejected.
BTW, I'm pretty certain that this patch breaks some valid cases
even if we take your point of view as correct. For one example,
you can't just remove the sort clause if the query uses DISTINCT ON.
regards, tom lane