Skip to content
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

Support space partitions per distinct value #544

Open
mbande opened this issue May 22, 2018 · 8 comments
Open

Support space partitions per distinct value #544

mbande opened this issue May 22, 2018 · 8 comments
Labels
core feature-request Feature proposal

Comments

@mbande
Copy link

mbande commented May 22, 2018

I have a table with an integer field that takes limited values 1,2,3.
and I want to space partition by this field, one partition for each value, i.e. to create 3 partitions and use value as exact partition id.
searching the documentation, I cant figure out an easy solution for this.

@LeeHampton
Copy link
Contributor

You can specify a custom partitioning function (see explanation for the partitioning_func argument here). With that you can control which partition a given element gets sent to. You can't directly control the exact partitioning id, however.

@mbande
Copy link
Author

mbande commented May 23, 2018

So, to enforce 1 partition per field value, i should initialize hypertable with 3 space partition and use an identity (f(x)->x) partitioning function, right?

@erimatnor
Copy link
Contributor

@mbande the function can't be the identity function. The purpose of the partitioning function is to map a value onto a int32 (positive) key space. That key space is then divided evenly across the number of partitions. So, for three partitions and an input value of 1, the partitioning function needs to output a positive int32 between 0 and INT32_MAX/3. For 2 and 3 it would be analogous but falling instead into the two remaining ranges.

@bartpeeters
Copy link

We have the exact same usecase, any plans to add this as a new feature? More generic would be a possibility to dynamically add new partitions, just how a hypertable makes new partitions based on time ranges, but in this case based on unique ids.

@adrianog
Copy link

Where can I find more info about partitioning_func? An example that goes through defining the function and passing it to create_hypertable?

I only see this entry in the documentation:
SELECT create_hypertable('conditions', 'time', 'location', 4, partitioning_func => 'location_hash');

@erimatnor
Copy link
Contributor

Related to #563

@bboule bboule added the core label Feb 19, 2020
@mfreed mfreed changed the title Space Partition one per value Support space partitions per distinct value Oct 18, 2020
@NunoFilipeSantos NunoFilipeSantos added feature-request Feature proposal and removed community-request labels Sep 28, 2021
@muntdan
Copy link

muntdan commented Nov 3, 2023

Any update on this please?

@muntdan
Copy link

muntdan commented Nov 4, 2023

I belive this might work:
If you want let's say 100 Tenant/partition and use smallint to count them from 0 to 99.
Because 2147483647/100 = 21474836, the function would look like this:

CREATE OR REPLACE FUNCTION SinglePartition(tenant anyelement) RETURNS 
integer AS 
$$
BEGIN
 RETURN tenant::smallint * 21474836 + 1;
END;
$$ 
LANGUAGE plpgsql IMMUTABLE;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core feature-request Feature proposal
Projects
None yet
Development

No branches or pull requests

10 participants