-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql/kv: don't step external read snapshot on volatile UDF execution #104847
Comments
I don't believe this is true, unless I'm misunderstanding what you mean. Future invocations of the UDF (or other UDFs) need to see all the writes of previous invocations of the UDF. Here's an example in Postgres: CREATE TABLE filter_counter (
i INT
);
INSERT INTO filter_counter VALUES (0);
CREATE FUNCTION incr_filter_counter() RETURNS BOOL LANGUAGE SQL AS $$
UPDATE filter_counter SET i = i + 1;
SELECT true;
$$;
SELECT * FROM generate_series(1, 5) WHERE incr_filter_counter();
SELECT * FROM filter_counter;
-- i
-- ---
-- 5
-- (1 row If each invocation of |
I think future invocations of the UDF would still see all the writes of previous invocations from the same txn. (This issue is about the UDF seeing writes from other txns.) |
That should only be an issue under Read-Committed isolation, correct? |
Right, when invoking volatile UDFs, all transactions will The question here is whether Read Committed txns (and only RC txns) should also step their external read snapshot when invoking volatile UDFs, so that each UDF gets an updated view of all other transactions in the system each time it is run. My understanding is that this is how PG works (relevant source code), but to do so they then play a subtle dance of snapshot management to restore the prior read snapshot when back in the calling statement's context. There are a few reasons why we might want to diverge from this behavior:
Answering the first question is probably the place to start. Are we aware of any UDFs that rely on seeing newly committed rows from other transactions ("new" relative to the start of their current statement)? The only example I've been able to come up with that might make some sense is a "succeeds soon" condition where a statement hangs in a backoff loop, repeatedly executing a volatile UDF until it observes some other txn commit. |
Hi @michae2, please add branch-* labels to identify which branch(es) this release-blocker affects. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
I think this is exactly the type of use we will (eventually) find in the wild. Some volatile UDF being called in a PLpgSQL loop waiting for another transaction to commit. |
In #100133 / #104362, we added support for per-statement read snapshots under Read Committed by updating the
Txn.Step
API to advance the transaction's read timestamp. This is correct for most callers of the API, but it appears that the following caller only wants to advance the txn's visibility of its own writes, not all other writes:cockroach/pkg/sql/routine.go
Lines 173 to 179 in bc1a2a0
This might motivate an expansion of the Step API. For example, we may want it to take a flag that indicates whether only the txn's internal read seq should be advanced or whether its internal read seq and its external read timestamp should be advanced (assuming Read Committed).
Jira issue: CRDB-28746
The text was updated successfully, but these errors were encountered: