citus icon indicating copy to clipboard operation
citus copied to clipboard

create_time_partitions and drop_old_time_partitions with less lock.

Open icefairy opened this issue 1 year ago • 9 comments

DESCRIPTION: PR description that will go into the change log, up to 78 characters from:https://www.postgresql.org/docs/14/sql-createtable.html

Note that creating a partition using PARTITION OF requires taking an ACCESS EXCLUSIVE lock on the parent partitioned table. Likewise, dropping a partition with DROP TABLE requires taking an ACCESS EXCLUSIVE lock on the parent table. It is possible to use ALTER TABLE ATTACH/DETACH PARTITION to perform these operations with a weaker lock, thus reducing interference with concurrent operations on the partitioned table.

icefairy avatar Feb 27 '24 05:02 icefairy

@microsoft-github-policy-service agree

icefairy avatar Feb 27 '24 05:02 icefairy

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.68%. Comparing base (f424268) to head (7e12c7d). Report is 22 commits behind head on main.

:exclamation: Current head 7e12c7d differs from pull request most recent head 5683a2b. Consider uploading reports for the commit 5683a2b to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7540      +/-   ##
==========================================
- Coverage   89.68%   89.68%   -0.01%     
==========================================
  Files         282      283       +1     
  Lines       60420    60428       +8     
  Branches     7523     7525       +2     
==========================================
+ Hits        54187    54193       +6     
- Misses       4079     4082       +3     
+ Partials     2154     2153       -1     

codecov[bot] avatar Feb 27 '24 12:02 codecov[bot]

Thank you for the contribution. This seems like a really nice improvement. For it to actually do something you have to create the relevant 12.2-1.sql files by copying latest.sql. See here for details: https://github.com/citusdata/citus/blob/main/CONTRIBUTING.md#changing-or-creating-functions

JelteF avatar Mar 08 '24 16:03 JelteF

done

icefairy avatar Mar 29 '24 10:03 icefairy

Ah, sorry I guess I wasn't clear before. You shouldn't update the old sql files. You should create:

  • src/backend/distributed/sql/udfs/create_time_partitions/12.1-1.sql
  • src/backend/distributed/sql/udfs/drop_old_time_partitions/12.1-1.sql

And #include those in: src/backend/distributed/sql/citus--12.0-1--12.1-1.sql

And do the reverse includes in: src/backend/distributed/sql/downgrades/citus--12.1-1--12.0-1.sql

JelteF avatar Apr 10 '24 16:04 JelteF

I think it's no need to modify downgrades script yes?

icefairy avatar Apr 29 '24 08:04 icefairy

I'm sorry, I messed up the version numbers in my previous message. Corrected below:

You shouldn't update the old sql files. You should create:

  • src/backend/distributed/sql/udfs/create_time_partitions/12.2-1.sql
  • src/backend/distributed/sql/udfs/drop_old_time_partitions/12.2-1.sql

And #include those in: src/backend/distributed/sql/citus--12.1-1--12.2-1.sql

And do the reverse includes in: src/backend/distributed/sql/downgrades/citus--12.2-1--12.1-1.sql

JelteF avatar Apr 29 '24 08:04 JelteF

file renamed

icefairy avatar May 06 '24 09:05 icefairy

You didn't do this part yet:

And #include those in: src/backend/distributed/sql/citus--12.1-1--12.2-1.sql

And do the reverse includes in: src/backend/distributed/sql/downgrades/citus--12.2-1--12.1-1.sql

And you also need to update the latest.sql files to be the same content as the new 12.2-1.sql files.

Finally, could you undo the removal of the trailing new line in these files. No changes should be necessary to these files at all:

  • src/backend/distributed/sql/udfs/create_time_partitions/10.2-1.sql
  • src/backend/distributed/sql/udfs/drop_old_time_partitions/12.0-1.sql

JelteF avatar May 06 '24 09:05 JelteF