-
Notifications
You must be signed in to change notification settings - Fork 7
MODSOURMAN-1204: Using a partitioned journal_records table #920
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
base: master
Are you sure you want to change the base?
Conversation
|
# Conflicts: # mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_record_processing_log_function.sql
…ord-manager into MODSOURMAN-1204
Code Review for MODSOURMAN-1204: Database Partitioning Migration and Related UpdatesOverview of the code changes: This branch introduces database table partitioning for journal records by entity type, updates Lombok version, adds tenant_id to SQL queries, and includes additional test logging. The main feature implements a partitioning strategy to improve query performance by segmenting journal records based on entity types. Files Changed:
Suggestions🔧 Missing SQL Transaction Management in Migration Script
BEGIN;
-- Create partitioned table structure
CREATE TABLE IF NOT EXISTS ${myuniversity}_${mymodule}.journal_records_entity_type (
-- ... existing definition
);
-- Create partitions
-- ... existing partition creation
-- Migrate data with error handling
INSERT INTO ${myuniversity}_${mymodule}.journal_records_entity_type (...)
SELECT ... FROM ${myuniversity}_${mymodule}.journal_records;
-- Create indexes
-- ... existing index creation
-- Rename tables atomically
ALTER TABLE ${myuniversity}_${mymodule}.journal_records RENAME TO journal_records_backup;
ALTER TABLE ${myuniversity}_${mymodule}.journal_records_entity_type RENAME TO journal_records;
COMMIT;🔧 Potential Data Loss Risk in Migration
CREATE TABLE IF NOT EXISTS ${myuniversity}_${mymodule}.journal_records_default PARTITION OF journal_records_entity_type DEFAULT;⛏️ Typo in SQL Comment
--ANALYZE VERBOSE ${myuniversity}_${mymodule}.journal_records;🔧 Missing Error Handling in Data Migration
-- Validate data before migration
DO $$
BEGIN
IF (SELECT COUNT(*) FROM ${myuniversity}_${mymodule}.journal_records WHERE entity_type NOT IN
('MARC_BIBLIOGRAPHIC', 'PO_LINE', 'MARC_HOLDINGS', 'MARC_AUTHORITY',
'HOLDINGS', 'AUTHORITY', 'INSTANCE', 'ITEM', 'ORDER', 'INVOICE', 'EDIFACT', '', NULL)) > 0 THEN
RAISE EXCEPTION 'Unexpected entity_type values found. Please review data before migration.';
END IF;
END $$;👍 Good Practice: Lombok Version Update
🔧 Incomplete Index Strategy for Partitioned Table
-- Add indexes on individual partitions for better query performance
CREATE INDEX CONCURRENTLY IF NOT EXISTS journal_records_marc_bib_job_exec_idx
ON ${myuniversity}_${mymodule}.journal_records_marc_bibliographic (job_execution_id);
CREATE INDEX CONCURRENTLY IF NOT EXISTS journal_records_marc_bib_source_idx
ON ${myuniversity}_${mymodule}.journal_records_marc_bibliographic (source_id);
-- Repeat for other high-traffic partitions💭 Consider Impact on Existing Queries
⛏️ Excessive Logging in Tests
.then()
.log().ifValidationFails() // Only log on failures
.statusCode(HttpStatus.SC_OK)👍 Good Addition: Stronger Test Assertions
📝 Missing Documentation for Schema Version
🔧 SQL Query Modification Impact Analysis Needed
🌱 Future Consideration: Partition Pruning Optimization
❓ Question: Rollback Strategy
SummaryThis code review identified several critical issues that should be addressed before deployment: Critical Issues (🔥):
High Priority Issues (
Positive Aspects (👍):
Recommendations:
The partitioning migration is a significant database change that requires careful testing in a staging environment before production deployment. |
|
This is an experimental PR to test one of the ideas for speeding up the receiving of import results from the DB. |



Purpose
Using a partitioned journal_records table for increase performance for DI summary
Approach
SQL script for converting journal_records table as partitioned table.
Learn
MODSOURMAN-1204