GithubHelp home page GithubHelp logo

Comments (10)

JanKaul avatar JanKaul commented on July 28, 2024 2

That would be cool. If you point me to where I could get started, I could try to implement it.

I guess the following steps are required:

  1. Define how sharding keys should be specified in pgcat.toml. Possible solutions could be a list of entries like ["data.id","dependent.data_id"] or a map like { data = id, dependent = data_id }
  2. Adopt serde to serialize the entries into a hashmap that maps tables to sharding keys.
  3. Adopt sqlparser to check for all sharding keys in Hashmap

I guess I know what I should do to solve the first two steps. But I'm not really sure how to do the last one.

from pgcat.

JanKaul avatar JanKaul commented on July 28, 2024 1

Thanks! I will look into it. I will hopefully find some time in the next couple of days.

from pgcat.

levkk avatar levkk commented on July 28, 2024

Hi there,

Thank you for filing an issue. Could you give me a couple examples when the custom SQL syntax breaks compatibility with existing systems?

Thanks!

from pgcat.

JanKaul avatar JanKaul commented on July 28, 2024

Hi,

First of all, thanks for all your contributions, this is an awesome project.

I would like to use pgcat with postgrest. It currently doesn't support the custom SQL from pgcat.

And I would expect that ORM systems also don't support the custom SQL syntax.

from pgcat.

levkk avatar levkk commented on July 28, 2024

Ah yes, this is expected.

For this reason, we've introduced a couple more ways to handle sharding:

  • using comments and parsing them with regex, e.g. /* sharding_key: 5 */ SELECT * FROM table_x WHERE id = 5; See regex_* settings in pgcat.toml.
  • automatically by parsing the SQL with sqlparser crate, that can be configured with automatic_sharding_key setting in pgcat.toml

What I usually see people do is extend their ORMs to allow for working with pgcat and sharding. Of course that's not possible or desirable for everyone so automatic sharding is the north star for us. If you could test it on your end and tell us how it's working for you, that would be great. We also welcome PRs if you find any areas of improvement.

Your proposal could also work, although I'm not entirely sure why you can't issue a SET SHARD TO query instead of the query you've proposed. Is that something inherent to postgrest that limits you to only writing queries against tables?

Let me know if any of those work for you.

from pgcat.

JanKaul avatar JanKaul commented on July 28, 2024

Thank you for your suggestions. I will have look at them. Especially the automatic sharding sounds interesting. Somehow I missed that feature before.

I will report my findings.

Postgrest maps the CRUD operations on a table to the http methods: POST, GET, PATCH, DELETE on a specific route. That's why the capabilities apart from the table operations is somewhat limited.

from pgcat.

JanKaul avatar JanKaul commented on July 28, 2024

The automatic sharding looks great and it almost solves my use case. To entirely solve my problem I would need to define automatic sharding keys for multiple tables, but as I understood this is not supported.

I have one table with the actual sharding key and then dependent tables referencing the sharding key as a foreign key. I would need to also shard the dependent tables according to the foreign key.

from pgcat.

levkk avatar levkk commented on July 28, 2024

We can add support for multiple sharding keys. I was already thinking about that, because foreign keys is a very common use case.

from pgcat.

levkk avatar levkk commented on July 28, 2024

For 3, take a look at query_router.rs, specifically: https://github.com/levkk/pgcat/blob/master/src/query_router.rs#L568

Convert this to a for each sharding key loop and match all of them. We dedup on shard values later and only allow to query one shard per query.

from pgcat.

JanKaul avatar JanKaul commented on July 28, 2024

I finally had time to work on the sharding keys. I created a PR that should enable multiple automatic sharding keys. If I'm not completely mistaken it was surprisingly simple to implement.

from pgcat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.