Skip to content

Support RETURNING in modification commands #242

Closed

Description

@citus-github-bot

Issue by digi604
Thursday Jul 23, 2015 at 15:23 GMT
Originally opened as citusdata/pg_shard#128


Any query using the RETURNING clause produces the following error:

NotSupportedError: cannot perform distributed planning for the given query
DETAIL:  RETURNING clauses are not supported in distributed queries.

Can you add support for RETURNING clauses?

Activity

  1. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by jasonmp85
    Monday Jul 27, 2015 at 19:56 GMT


    Hey Patrick Lauber (@digi604): What's your use case? We didn't implement RETURNING to keep the feature profile abbreviated during the initial release, but with sufficient demand we could change that. 😃

  2. added
    feature
    on Feb 4, 2016
  3. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by rodo
    Sunday Aug 09, 2015 at 17:05 GMT


    In ORM (I know it's bad, but sometimes we have to work with people who love them) like Django the SQL query include RETURNING to return the object's id to the ORM, maybe Patrick Lauber (@digi604) uses an ORM.
    I vote for RETURNING support in pg_shard 👍

  4. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by digi604
    Tuesday Aug 11, 2015 at 07:52 GMT


    i use peewee (orm) in a rather complex worker queue.

  5. ozgune commented on Mar 16, 2016

    @ozgune
    Contributor

    This feature came up again. If the query executed on a single shard, how hard would it be to implement? Would we need to keep the returned values from INSERT statements on the master node?

    ORMs like to have their INSERT statements to have RETURNING expressions:

    returning id -- returning null
    FEELINGS_DB.run(Sequel.lit("insert into observation_hash(id, created_at, server_id, data)
      values(?,?,?,?)",
      (feeling_id+i).to_s(16).rjust(32,'0'),
      Time.now,
      (server_id+i).to_s(16).rjust(32,'0'),
      data
    ))
    # vs
    FEELINGS_DB[:observation_hash] << {
      id: (feeling_id+i).to_s(16).rjust(32,'0'),
      created_at: Time.now,
      server_id: (server_id+i).to_s(16).rjust(32,'0'),
      data: dat
    
  6. ozgune commented on Mar 18, 2016

    @ozgune
    Contributor

    I just chatted with Andres Freund (@anarazel) on this. We have two ways to implement this:

    1. Execute the RETURNING statement on the master node: Andres Freund (@anarazel) notes that this approach is much easier to integrate into the PostgreSQL machinery. Andres, could you note this approach's benefits?
    2. Push the RETURNING statement to the worker node. In this approach, we'll push down the query and store results returned from the worker node in a tuple store. In this approach, we could also cover UPDATE statements that touch a single shard.

    I'm also noting #213 and #240 as semi-related issues. At a higher level, we could evaluate expressions on the master node and route these requests, or evaluate them on the workers. This decision may also relate to our replication model.

  7. jasonmp85 commented on Mar 18, 2016

    @jasonmp85
    Contributor

    Hey Ozgun Erdogan (@ozgune)

    I don't understand what executing this on the master even means. RETURNING is part of an UPDATE, INSERT, or DELETE command that returns a particular column. It would make the most sense to push this down.

    Approach two is what I was going to suggest.

  8. anarazel commented on Mar 18, 2016

    @anarazel
    Contributor

    Jason Petersen (@jasonmp85) The point of not pushing RETURNING down, at the very least for INSERT, is that it a) allows for easy and correct evaluation of now(), nextval(), etc. b) doesn't prevent going to a pipelined execution model c) is actually easier to implement given how RETURNING works in postgres.

  9. jasonmp85 commented on Mar 18, 2016

    @jasonmp85
    Contributor

    Right, but what about UPDATE count = count + 1 RETURNING count? Isn't stuff like that a pretty common pattern, too? Or DELETE FROM accounts WHERE id = 5 RETURNING balance? That is more straightforward if you push the clause down, no?

  10. anarazel commented on Mar 18, 2016

    @anarazel
    Contributor

    On 2016-03-17 21:07:23 -0700, Jason Petersen wrote:

    Right, but what about UPDATE count = count + 1 RETURNING count?
    Isn't stuff like that a pretty common pattern, too? Or DELETE FROM accounts WHERE id = 5 RETURNING balance? That is more
    straightforward if you push the clause down, no?

    True. But those are much less common. The most common reason to use
    RETURNING is for ORMs after an INSERT, to get the generated key et al.

  11. samay-sharma commented on Apr 12, 2016

    @samay-sharma
    Contributor

    Ran into this again during a customer engagement. It was again because their ORM was issuing INSERT queries which had a RETURNING clause.

  12. brettallred commented on Apr 14, 2016

    @brettallred

    +1 - We are running into the same issue while evaluating CitusDB

  13. 16 remaining items

  14. added a commit that references this issue on Jun 3, 2016
    5a0c4cd
  15. added
    needs-review
    and removed on Jun 22, 2016
  16. removed
    needs-review
    on Jul 1, 2016
  17. added a commit that references this issue on Jan 10, 2018
    586f738
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

featurepriority:high

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions