Skip to content

Allow references to columns in UPDATE statements - #472

Merged
Brian Cloutier (lithp) merged 7 commits into
masterfrom
240-allow-non-constant-updates
Apr 28, 2016
Merged

Brian Cloutier (lithp) merged 7 commits into
masterfrom
240-allow-non-constant-updates

Conversation

@lithp

@lithp Brian Cloutier (lithp) commented Apr 26, 2016 •

Copy link
Copy Markdown
Contributor

Fix #240

To do:

  • Find a better place to put the new tests?
  • Do we need to update any more planners than the router planner?
  • What is a TargetEntry in an INSERT or DELETE statement? Add tests for those too?
  • Also change the error message?

@lithp Brian Cloutier (lithp) added this to the 5.1 Release milestone Apr 26, 2016
@lithp Brian Cloutier (lithp) added the needs-review to track proposals or requests that are pending review to triage label Apr 26, 2016
@@ -0,0 +1,30 @@
CREATE TABLE modifications (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to add a test file? Why not using multi_modifications.sql ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because waiting for that comment was easier than searching for the right place myself :) Moved the tests there and rebased.

@lithp
Brian Cloutier (lithp) force-pushed the 240-allow-non-constant-updates branch from 873baf0 to 2503e07 Compare April 27, 2016 09:06
@lithp Brian Cloutier (lithp) changed the title [WIP] Allow references to columns in UPDATE statements Allow references to columns in UPDATE statements Apr 27, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 335 there is a check for IsA(setTargetEntry->expr, Var). Do you or Önder Kalacı (@onderkalaci) know why there is an explicit check for that. Is there a case that it not covered by contain_mutable_functions that we can support, or is this something specific to upsert?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's covered by contain_mutable_functions. Onder says they added it to be explicit that naked Var's are allowed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a test for that as well if you'd like

@lithp
Brian Cloutier (lithp) force-pushed the 240-allow-non-constant-updates branch from 5fe50bf to 693a797 Compare April 28, 2016 10:58
gm | 247
(1 row)

-- updates referencing an unpure function are unsupported

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what unpure means. PostgreSQL distinguishes between immutable, stable, and volatile. Only the first one is allowed. I think you mean pure -> immutable, unpure -> volatile.

@lithp Brian Cloutier (lithp) Apr 28, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been doing too much functional programming, updated the comments

@marcocitus

Copy link
Copy Markdown
Contributor

Since there's an open TODO for it: Do we need to update the error message?

@lithp

Copy link
Copy Markdown
Contributor Author

How about

Cannot plan sharded motification containing expressions which invoke mutable functions

@lithp

Copy link
Copy Markdown
Contributor Author

Right now we say:

cannot plan sharded modification containing values which are not constants or constant expressions

But it looks like every codepath which emits that message now checks for mutable functions in the expression

@marcocitus

Copy link
Copy Markdown
Contributor

"Mutable" is not really used in PostgreSQL documentation, so I'm not sure if users can easily understand what it means.

Maybe something similar to PostgreSQL's error message:

postgres=# CREATE INDEX ON foo ((now()));
ERROR:  functions in index expression must be marked IMMUTABLE

e.g.

ERROR:  functions in modification queries on distributed tables must be marked IMMUTABLE

@marcocitus

Copy link
Copy Markdown
Contributor

A nice future enhancement would be to skip all these checks when the replication factor is 1.

@marcocitus

Copy link
Copy Markdown
Contributor

Pending squashing: 🚢

@lithp
Brian Cloutier (lithp) merged commit 0036eb3 into master Apr 28, 2016
@lithp Brian Cloutier (lithp) removed the needs-review to track proposals or requests that are pending review to triage label Apr 28, 2016
@jasonmp85
Jason Petersen (jasonmp85) deleted the 240-allow-non-constant-updates branch April 28, 2016 17:14
@jasonmp85

Copy link
Copy Markdown
Contributor

If we start allowing more than one UPDATE to hit a shard at once, this introduces race conditions… didn't know this was going to be merged so quickly.

@lithp

Copy link
Copy Markdown
Contributor Author

I assumed we already locked, because that's equally true of concurrent a =
3 and a = 5 updates, which we already supported.

28 Nis 2016 Per 21:55 tarihinde Jason Petersen [email protected]
şunu yazdı:

If we start allowing more than one UPDATE to hit a shard at once, this
introduces race conditions… didn't know this was going to be merged so
quickly.

—
You are receiving this because you modified the open/close state.

Reply to this email directly or view it on GitHub
#472 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants