|
|
|
|
|
by jd3
584 days ago
|
|
A week before being laid off last month, I solved a decade+ old open problem at our company which first occurred since Django doesn't natively support CTE's, leading to years of technical debt from the ersatz sql/query plans produced by our fragile queries. I ended up manually overloading get_extra_restriction on a custom ForeignKey class (we couldn't use FilteredRelation b/c we were still on django 1.11), which ensured that the JOIN ON ... clause limited the tables being joined to their correct partition/schema while being accessed through a view The view thing is a long story — it was a legacy PAC codebase from the '90s which used 13+ schemas in a mysql db that was then being synced to our postgres db through Amazon DMS. All of the tables on each view contain identical source_schema/CompanyID columns, hence the '%(remote_alias)s. "source_schema" = %(fk_alias)s. "source_schema" AND '
'%(remote_alias)s. "CompanyID" = %(fk_alias)s. "CompanyID"
etc. approachbefore/after query plan in depesz: https://imgur.com/a/HQbNSIL |
|
As an aside why not use postgres's mysql foreign data wrapper instead of syncing with the mysql database?