Re: Allowing DML RULEs that produce Read Only actions during RO xacts

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Simon Riggs <simon@2ndQuadrant.com>
Cc: pgsql-hackers@postgresql.org
Date: 2009-12-06T15:26:48Z
Lists: pgsql-hackers
Simon Riggs <simon@2ndQuadrant.com> writes:
> I would like to allow RULEs ON INSERT, ON UPDATE and ON DELETE during
> read only transactions iff they generate only SELECT statements that act
> INSTEAD OF the actual event.

I don't actually believe there is any use case for such a thing.

> This would be a small, but useful additional feature for Hot Standby,
> since it would allow INSERT, UPDATE, DELETE statements to be re-routed,
> for various applications.

How would you "reroute" them without a non-read-only operation happening
somewhere along the line?
 
> +	/*
> +	 * If we're running a SELECT, allow it. This ensures that a
> +	 * write rule such as ON INSERT DO SELECT can be executed in
> +	 * a read-only session.
> +	 */
> +	if (plannedstmt->commandType == CMD_SELECT)
> +		return;

This will fail, very nastily, in writable-CTE cases.

			regards, tom lane