Subject: Altering the SELECT portion of a CREATE TABLE AS plan

From: Jerry Sievert <[email-masked]>
Date: Thu, 24 Aug 2023 08:42:57 -0700

Hi, i am trying to mutate a plan for a T_CreateTableAsStmt before it executes.

I've created a planner_hook_type hook, where i can see the plan that gets executed as part of the AS of the query, where the CmdType is CMD_SELECT, and its subplans are the plans for the actual select itself.

I've also created a ProcessUtility_hook_type, which correctly shows the T_CreateTableAsStmt, but the hook is called after the actual CREATE TABLE is called, and the plan is no longer mutable for the part that i need.

Is there another hook i should be looking at, or another way i should be approaching this?  I need to be able to alter the plan specifically for the SELECT portion of a CREATE TABLE AS query, but only in the case of the SELECT TABLE AS, and in no other SELECTs.

Alternately, I can look at the query string in the CMD_SELECT planner hook and search specifically for CREATE, TABLE and AS, but I feel that there has to be a better way, and look forward to some guidance.

Thanks!