Better implementation of CREATE TABLE AS ... WITH NO DATA

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Better implementation of CREATE TABLE AS ... WITH NO DATA
Дата
Msg-id 27375.1322162573@sss.pgh.pa.us
обсуждение исходный текст
Список pgsql-hackers
In
http://archives.postgresql.org/message-id/52CCAA8F414BA8anzai-naoya@mxu.nes.nec.co.jp
it's pointed out that our documentation claims the WITH [NO] DATA option
works for all variants of CREATE TABLE AS.  But in fact it's only
implemented for the SelectStmt variant, not for the ExecuteStmt variant,
and the ugly kluge used for SelectStmt (paste on a LIMIT 0 at parse
time) isn't going to work for the ExecuteStmt case.

What I'm considering doing to improve this is to add a bool field
"skipData" or some such to IntoClause.  By default that would be false,
but the CREATE TABLE AS productions could set it true when they have
WITH NO DATA.  Then we'd need to add an execution-time test; the most
expedient way seems to be to add something like this to ExecutorRun:
if (estate->es_select_into &&    queryDesc->plannedstmt->intoClause->skipData)    direction = NoMovementScanDirection;

which will cause it to skip the ExecutePlan call.  In the normal case
this adds just one boolean test to ExecutorRun, so I don't think it
represents a measurable slowdown.  The EXECUTE code path needs no
changes since it's just passing the IntoClause through to the executor.

While at it, it occurs to me that we could handle the
IntoClause.colNames option for the ExecuteStmt case if we were to move
the responsibility for plastering on the substitute column names into
the executor's OpenIntoRel, instead of making parse analysis do this
(which is also pretty klugy, see applyColumnNames callers).

Any objections or better ideas?
        regards, tom lane


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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: Obstacles to user-defined range canonicalization functions
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Notes on implementing URI syntax for libpq