-
Notifications
You must be signed in to change notification settings - Fork 1
PRSD-1023: Efficient LA Property Search #836
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: main
Are you sure you want to change the base?
Changes from all commits
45ea4a9
91f7fda
aeb5330
f610148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| ALTER TABLE property_ownership | ||
| ADD single_line_address VARCHAR(1000) DEFAULT '' NOT NULL; | ||
|
|
||
| UPDATE property_ownership po SET single_line_address = ( | ||
| SELECT a.single_line_address | ||
| FROM address a | ||
| JOIN property p ON a.id = p.address_id | ||
| WHERE p.id = po.property_id | ||
| ); | ||
|
|
||
| CREATE FUNCTION update_property_ownership_single_line_address() | ||
| RETURNS TRIGGER | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| DECLARE | ||
| propertyOwnershipId BIGINT; | ||
| propertyId BIGINT; | ||
| addressId BIGINT; | ||
| BEGIN | ||
| CASE | ||
| WHEN TG_TABLE_NAME = 'property_ownership' THEN | ||
| propertyOwnershipId := NEW.id; | ||
| UPDATE property_ownership po SET single_line_address = ( | ||
| SELECT a.single_line_address | ||
| FROM address a | ||
| JOIN property p ON a.id = p.address_id | ||
| WHERE p.id = po.property_id | ||
| ) | ||
| WHERE po.id = propertyOwnershipId; | ||
|
|
||
| WHEN TG_TABLE_NAME = 'property' THEN | ||
| propertyId := NEW.id; | ||
| UPDATE property_ownership po SET single_line_address = ( | ||
| SELECT a.single_line_address | ||
| FROM address a | ||
| JOIN property p ON a.id = p.address_id | ||
| WHERE p.id = property_id | ||
| ) | ||
| WHERE po.property_id = propertyId; | ||
|
|
||
| WHEN TG_TABLE_NAME = 'address' THEN | ||
| addressId := NEW.id; | ||
| UPDATE property_ownership po SET single_line_address = ( | ||
| SELECT a.single_line_address | ||
| FROM address a | ||
| WHERE a.id = addressId | ||
| ) | ||
| WHERE po.property_id = (SELECT p.id FROM property p WHERE p.address_id = addressId); | ||
| END CASE; | ||
| RETURN NULL; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE TRIGGER insert_property_ownership_single_line_address | ||
| AFTER INSERT ON property_ownership | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION update_property_ownership_single_line_address(); | ||
|
|
||
| CREATE TRIGGER update_property_ownership_single_line_address | ||
| AFTER UPDATE OF property_id ON property_ownership | ||
isobel-softwire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| FOR EACH ROW | ||
| WHEN (OLD.property_id IS DISTINCT FROM NEW.property_id) | ||
| EXECUTE FUNCTION update_property_ownership_single_line_address(); | ||
|
|
||
| CREATE TRIGGER update_property_ownership_single_line_address | ||
| AFTER UPDATE OF address_id ON property | ||
isobel-softwire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| FOR EACH ROW | ||
| WHEN (OLD.address_id IS DISTINCT FROM NEW.address_id) | ||
| EXECUTE FUNCTION update_property_ownership_single_line_address(); | ||
|
|
||
| CREATE TRIGGER update_property_ownership_single_line_address | ||
| AFTER UPDATE OF single_line_address ON address | ||
| FOR EACH ROW | ||
| WHEN (OLD.single_line_address IS DISTINCT FROM NEW.single_line_address) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this approach not massively slow down the seeding of the DB with NGD address data?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been removed as we'll be referencing property ownerships from addresses rather than the other way around
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, querying the address table is much slower than querying the property ownership table, even with a partial index. I'll go back to referencing addresses from property ownerships. To combat slowing down NGD data loading, we can refresh the addresses once after loading finishes, rather than using this trigger.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intrigued that it takes longer - would expect it to be at least similar - but yes, if we can update them for each batch in one go during ingest instead of using the trigger that should at least limit the slow-down there |
||
| EXECUTE FUNCTION update_property_ownership_single_line_address(); | ||
|
|
||
| CREATE INDEX property_ownership_single_line_address_idx ON property_ownership USING gist (single_line_address gist_trgm_ops(siglen=2024)) WHERE is_active; | ||
Uh oh!
There was an error while loading. Please reload this page.