choose correct partition pivot and denormalization for withdraw-age related tables

This commit is contained in:
Özgür Kesim 2023-01-11 15:23:51 +01:00
parent 973c671679
commit e6929fd3ee
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
2 changed files with 26 additions and 19 deletions

View File

@ -29,13 +29,14 @@ BEGIN
',h_commitment BYTEA PRIMARY KEY CHECK (LENGTH(h_commitment)=64)' ',h_commitment BYTEA PRIMARY KEY CHECK (LENGTH(h_commitment)=64)'
',amount_with_fee_val INT8 NOT NULL' ',amount_with_fee_val INT8 NOT NULL'
',amount_with_fee_frac INT4 NOT NULL' ',amount_with_fee_frac INT4 NOT NULL'
',noreveal_index INT4 NOT NULL' ',max_age_group INT2 NOT NULL'
',reserve_uuid INT8 NOT NULL' -- TODO: can here be the foreign key reference? ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
',reserve_sig BYTEA CHECK (LENGTH(reserve_sig)=64)' ',reserve_sig BYTEA CHECK (LENGTH(reserve_sig)=64)'
',noreveal_index INT4 NOT NULL'
',timestamp INT8 NOT NULL' ',timestamp INT8 NOT NULL'
') %s ;' ') %s ;'
,table_name ,table_name
,'PARTITION BY HASH (reserve_uuid)' -- TODO: does that make sense? ,'PARTITION BY HASH (h_commitment)'
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_table( PERFORM comment_partitioned_table(
@ -49,6 +50,12 @@ BEGIN
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_column(
'The maximum age group that the client commits to with this request'
,'max_age_group'
,table_name
,partition_suffix
);
PERFORM comment_partitioned_column( PERFORM comment_partitioned_column(
'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol' 'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol'
,'h_commitment' ,'h_commitment'
@ -56,8 +63,8 @@ BEGIN
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_column( PERFORM comment_partitioned_column(
'Reference to the reserve from which the coins are goin to be withdrawn' 'Reference to the public key of the reserve from which the coins are going to be withdrawn'
,'reserve_uuid' ,'reserve_pub'
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
@ -89,14 +96,14 @@ BEGIN
table_name = concat_ws('_', table_name, partition_suffix); table_name = concat_ws('_', table_name, partition_suffix);
EXECUTE FORMAT ( EXECUTE FORMAT (
'CREATE INDEX ' || table_name || '_by_reserve_uuid' 'CREATE INDEX ' || table_name || '_by_reserve_pub'
' ON ' || table_name || ' ON ' || table_name ||
' (reserve_uuid);' ' (reserve_pub);'
); );
EXECUTE FORMAT ( EXECUTE FORMAT (
'ALTER TABLE ' || table_name || 'ALTER TABLE ' || table_name ||
' ADD CONSTRAINT ' || table_name || '_withdraw_age_commitment_id_key' ' ADD CONSTRAINT ' || table_name || '_withdraw_age_commitment_id_key'
' UNIQUE (withdraw_age_commitment_id)' ' UNIQUE (withdraw_age_commitment_id);'
); );
END END
$$; $$;
@ -111,9 +118,9 @@ DECLARE
BEGIN BEGIN
EXECUTE FORMAT ( EXECUTE FORMAT (
'ALTER TABLE ' || table_name || 'ALTER TABLE ' || table_name ||
' ADD CONSTRAINT ' || table_name || '_foreign_reserve_uuid' ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
' FOREIGN KEY (reserve_uuid) ' ' FOREIGN KEY (reserve_pub)'
' REFERENCES reserves (reserve_uuid) ON DELETE CASCADE' ' REFERENCES reserves (reserve_pub) ON DELETE CASCADE;'
); );
END END
$$; $$;

View File

@ -25,13 +25,13 @@ DECLARE
BEGIN BEGIN
PERFORM create_partitioned_table( PERFORM create_partitioned_table(
'CREATE TABLE %I' 'CREATE TABLE %I'
'(withdraw_age_commitments_id INT8 NOT NULL' -- TODO: can here be the foreign key reference? '(h_commitment BYTEA NOT NULL CHECK (LENGTH(h_commitment)=32)'
',freshcoin_index INT4 NOT NULL' ',freshcoin_index INT4 NOT NULL'
',denominations_serial INT8 NOT NULL' -- TODO: can here be the foreign key reference? ',denominations_serial INT8 NOT NULL'
',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=32)' ',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=32)'
') %s ;' ') %s ;'
,table_name ,table_name
,'PARTITION BY HASH (withdraw_age_commitments_id)' -- TODO: does that make sense? ,'PARTITION BY HASH (h_commitment)'
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_table( PERFORM comment_partitioned_table(
@ -41,7 +41,7 @@ BEGIN
); );
PERFORM comment_partitioned_column( PERFORM comment_partitioned_column(
'Foreign key reference to the corresponding commitment' 'Foreign key reference to the corresponding commitment'
,'withdraw_age_commitments_id' ,'h_commitment'
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
@ -76,15 +76,15 @@ DECLARE
BEGIN BEGIN
EXECUTE FORMAT ( EXECUTE FORMAT (
'ALTER TABLE ' || table_name || 'ALTER TABLE ' || table_name ||
' ADD CONSTRAINT ' || table_name || '_foreign_withdraw_age_commitment_id' ' ADD CONSTRAINT ' || table_name || '_foreign_h_commitment'
' FOREIGN KEY (withdraw_age_commitments_id) ' ' FOREIGN KEY (h_commitment)'
' REFERENCES withdraw_age_commitments (withdraw_age_commitment_id) ON DELETE CASCADE' ' REFERENCES withdraw_age_commitments (h_commitment) ON DELETE CASCADE;'
); );
EXECUTE FORMAT ( EXECUTE FORMAT (
'ALTER TABLE ' || table_name || 'ALTER TABLE ' || table_name ||
' ADD CONSTRAINT ' || table_name || '_foreign_denominations_serial' ' ADD CONSTRAINT ' || table_name || '_foreign_denominations_serial'
' FOREIGN KEY (denominations_serial) ' ' FOREIGN KEY (denominations_serial) '
' REFERENCES denominations (denominations_serial) ON DELETE CASCADE' ' REFERENCES denominations (denominations_serial) ON DELETE CASCADE;'
); );
END END
$$; $$;