-
Notifications
You must be signed in to change notification settings - Fork 10
feat: replace predicate_object with materialized view #175
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: feat/removing-fks
Are you sure you want to change the base?
feat: replace predicate_object with materialized view #175
Conversation
Pull Request Review: Replace predicate_object with Materialized ViewOverviewThis PR replaces the table-based Code Quality & Best PracticesStrengths✅ Cleaner architecture: Eliminates 145+ lines of complex trigger logic for maintaining aggregate tables Areas of Concern1. CRITICAL: Performance Impact of Statement-Level TriggerLocation: CREATE TRIGGER triple_term_refresh_views_trigger
AFTER INSERT OR UPDATE OR DELETE ON triple_term
FOR EACH STATEMENT
EXECUTE FUNCTION refresh_predicate_object_subject_predicate_views();Issue: The trigger performs a full refresh of both materialized views on every
Impact:
Recommendation: Consider one of these approaches:
2. Missing Down MigrationLocation: Issue: The down migration still attempts to: DROP TABLE IF EXISTS predicate_object;But these are now materialized views, not tables. The down migration should use: DROP MATERIALIZED VIEW IF EXISTS predicate_object;
DROP MATERIALIZED VIEW IF EXISTS subject_predicate;Impact: Rollback migrations will fail, making it difficult to revert this change in production if issues arise. 3. Missing Index Cleanup in Trigger Down MigrationLocation: Issue: The down migration drops old triggers/functions but doesn't address the new trigger:
Old references still exist: DROP TRIGGER IF EXISTS triple_predicate_object_trigger ON triple; -- Line 26
DROP FUNCTION IF EXISTS update_predicate_object_on_triple_insert(); -- Line 45Impact: Incomplete rollback capability; old function/trigger names no longer exist in up migration. 4. Data Migration StrategyQuestion: How is existing data in the The migration:
Recommendation: The migration should include: -- After creating the materialized views
REFRESH MATERIALIZED VIEW predicate_object;
REFRESH MATERIALIZED VIEW subject_predicate;This ensures the views are populated immediately and queries don't return empty results. Security Concerns
No direct security vulnerabilities identified. The change maintains the same data access patterns. Test Coverage❓ Testing Strategy: The PR has no description of test coverage. Consider:
Performance Considerations Summary
RecommendationsMust Fix
Should Consider
Nice to Have
Overall AssessmentThis is a promising simplification that could reduce maintenance burden, but the performance implications need careful evaluation. The statement-level trigger refreshing entire views on every Recommendation: Address the critical issues (down migration, initial refresh) before merging, and strongly consider moving to scheduled/batch refreshes rather than trigger-based refreshes. Happy to discuss any of these points further! 🚀 |
No description provided.