Re: COPY FROM WHEN condition
Tomas Vondra <tomas.vondra@2ndquadrant.com>
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Surafel Temsgen <surafel3000@gmail.com>, berlin.ab@gmail.com,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-12-08T13:36:38Z
Lists: pgsql-hackers
On 12/6/18 4:52 PM, Robert Haas wrote: > On Wed, Nov 28, 2018 at 6:17 PM Tomas Vondra > <tomas.vondra@2ndquadrant.com> wrote: >>> Comparing with overhead of setting snapshot before evaluating every row >>> and considering this >>> >>> kind of usage is not frequent it seems to me the behavior is acceptable >> >> I'm not really buying the argument that this behavior is acceptable >> simply because using the feature like this will be uncommon. That seems >> like a rather weak reason to accept it. >> >> I however agree we don't want to make COPY less efficient, at least not >> unless absolutely necessary. But I think we can handle this simply by >> restricting what's allowed to appear the FILTER clause. >> >> It should be fine to allow IMMUTABLE and STABLE functions, but not >> VOLATILE ones. That should fix the example I shared, because f() would >> not be allowed. > > I don't think that's a very good solution. It's perfectly sensible > for someone to want to do WHERE/FILTER random() < 0.01 to load a > smattering of rows, and this would rule that out for no very good > reason. > Good point. I agree that's a much more plausible use case for this feature, and forbidding volatile functions would break it. > I think it would be fine to just document that if the filter condition > examines the state of the database, it will not see the results of the > COPY which is in progress. I'm pretty sure there are other cases - > for example with triggers - where you can get code to run that can't > see the results of the command currently in progress, so I don't > really buy the idea that having a feature which works that way is > categorically unacceptable. > > I agree that we can't justify flagrantly wrong behavior on the grounds > that correct behavior is expensive or on the grounds that the > incorrect cases will be rare. However, when there's more than one > sensible behavior, it's not unreasonable to pick one that is easier to > implement or cheaper or whatever, and that's the category into which I > would put this decision. > OK, makes sense. I withdraw my objections to the original behavior, and agree it's acceptable if it's reasonably documented. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Commits
-
Remove unused struct member, enforce multi_insert callback presence.
- 57a7a3adfe4e 12.0 landed
-
Separate per-batch and per-tuple memory contexts in COPY
- 36a1281f86c0 12.0 landed
-
Fix handling of volatile expressions in COPY FROM ... WHERE
- 4a8283d0ec5a 12.0 landed
-
Allow COPY FROM to filter data using WHERE conditions
- 31f3817402da 12.0 landed
-
Remove obsolete netbsd dynloader code
- b68ff3ea672c 12.0 cited