Skip to content
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

Ensure _revision_expired is always > _revision_created #121

Closed
wants to merge 8 commits into from
Closed

Ensure _revision_expired is always > _revision_created #121

wants to merge 8 commits into from

Conversation

strk
Copy link
Contributor

@strk strk commented May 10, 2018

Closes #78

@strk strk self-assigned this May 10, 2018
@strk strk added this to the 1.5.0 milestone May 10, 2018
@strk strk requested a review from palmerj May 10, 2018 13:36
@strk
Copy link
Contributor Author

strk commented May 10, 2018

@imincik do you want to give this change a try and see how much does it affect performances ?

@imincik
Copy link
Contributor

imincik commented May 14, 2018

@strk , I would be interested if there are any other similar checks we can introduce.

@imincik
Copy link
Contributor

imincik commented May 14, 2018

I added @dwsilk to reviewers. I can test it in BDE Processor for performance penalty, but I am not sure if it will cover all use cases.

@imincik imincik requested a review from dwsilk May 14, 2018 11:01
@strk
Copy link
Contributor Author

strk commented May 14, 2018

@imincik yes, I think we could also introduce a foreign key constraint to make sure revisions used in _revision_created and _revision_expired DO exist in table_version.revision, but I wanted to first verify the performance change with just this single constraint

@dwsilk
Copy link
Member

dwsilk commented May 15, 2018

Okay so this should really only affect INSERT and UPDATE on the _revision tables, right?

Basic test to compare performance over 10,000,000 records with bare minimum data:

BEGIN; 

CREATE TABLE foo(id integer, _revision_created timestamp, _revision_expired timestamp);
CREATE TABLE bar(id integer, _revision_created timestamp, _revision_expired timestamp, CHECK (_revision_created < _revision_expired));

\timing on
INSERT INTO foo(id, _revision_created, _revision_expired) SELECT generate_series(1, 10000000), '2018-05-01', NULL;
INSERT INTO bar(id, _revision_created, _revision_expired) SELECT generate_series(1, 10000000), '2018-05-01', NULL;
UPDATE foo SET _revision_expired = '2018-05-05';
UPDATE bar SET _revision_expired = '2018-05-05';
\timing off

ROLLBACK;

Result:

Command Without CHECK With CHECK Performance Hit
INSERT 10,000,000 records 13430.308 ms 14061.644 ms 4.7% longer
UPDATE 10,000,000 records 30311.315 ms 30843.735 ms 1.8% longer

I would guess that BDE processor performance is the most important application that we can test. The amount of data in queries for other applications of this extension at LINZ is minimal in comparison.

@strk
Copy link
Contributor Author

strk commented May 16, 2018

Yes it should only affect INSERT/UPDATE (while foreign key constraint would also affect DELETE on the referenced table) - those hits seem ok to me, especially as for BDE processing the inserts and updates would be MORE expensive because there would be more data to write, while the cost of comparing _revision_expired and _revision_created would be fixed...

@strk
Copy link
Contributor Author

strk commented May 17, 2018 via email

dwsilk
dwsilk previously approved these changes May 17, 2018
@strk
Copy link
Contributor Author

strk commented May 17, 2018 via email

@imincik imincik self-requested a review June 13, 2018 07:44
@imincik
Copy link
Contributor

imincik commented Jun 13, 2018

I will test this PR with level_5 update. @strk , please wait with merge until this is done.

@imincik
Copy link
Contributor

imincik commented Aug 24, 2018

I just started performance test of this patch (running level_0 without patch). Might be done in 4 days from now.

@imincik
Copy link
Contributor

imincik commented Aug 24, 2018

@strk , level 0 processing using latest released packages, without tested patch, finished with following error:

COMMENT
COMMENT
SET
SET
INFO:  Patch BDE - 1.0.2: Remove annotations column from bde.crs_work is already applied
INFO:  Patch BDE 1.2.0 / LOL 3.17: Remove tan column from bde.crs_transact_type is already applied
INFO:  Patch BDE 1.2.0 / LOL 3.17: Add img_id and description columns to bde.crs_stat_act_parcl is already applied
DO
SET
ERROR:  Error versioning bde.cbe_title_parcel_association. ERROR: permission denied for relation pg_depend
CONTEXT:  PL/pgSQL function inline_code_block line 50 at RAISE
ERROR: Failure enabling table versioning in database bde

Ticket created: https://app.zenhub.com/workspace/o/linz/bde-processor-deployment/issues/307

@strk
Copy link
Contributor Author

strk commented Aug 27, 2018

Make sure the user who prepares the database (with table_version 1.5.0+) or the user who runs the upload (with table_version up to 1.4.x) is a superuser, or has permissions to write into pg_depend.

Example query: SELECT has_table_privilege('bde', 'pg_catalog.pg_depend', 'INSERT');

@strk strk modified the milestones: 1.5.0, 1.6.0 Sep 26, 2018
@stale
Copy link

stale bot commented Nov 10, 2018

This issue has been automatically marked as stale as there has not been any activity for sometime. The issue will be closed in 14 days if no further activity.

@stale stale bot added the Stale label Nov 10, 2018
@imincik
Copy link
Contributor

imincik commented Nov 10, 2018

This issue is still relevant.

@stale stale bot removed the Stale label Nov 10, 2018
@stale
Copy link

stale bot commented Nov 24, 2018

This issue has been automatically marked as stale as there has not been any activity for sometime. The issue will be closed in 14 days if no further activity.

@stale stale bot added the Stale label Nov 24, 2018
@palmerj palmerj removed their request for review March 20, 2019 08:54
@strk
Copy link
Contributor Author

strk commented Mar 21, 2019

It took 35147012.330 ms (9.7630 hours) to run LDS_MaintainSimplifiedLayers(0) with lds and bde_ext tables versioned and NO integrity check. I'm not running it again with the integrity check.

@imincik
Copy link
Contributor

imincik commented Mar 21, 2019

Where are you running those tests ? LI-exp ? Looks too long, maybe somebody was running something else there as well.

@strk
Copy link
Contributor Author

strk commented Mar 25, 2019

Completed same run (yes, on li-exp) with this PR applied. Took 42038905.988 ms (~11.6 hrs)

@imincik
Copy link
Contributor

imincik commented Mar 25, 2019

Hm, look very slow ...

@strk strk removed this from the 1.7.0 milestone Jul 25, 2019
@strk
Copy link
Contributor Author

strk commented Sep 12, 2019

We could try an INITIALLY DEFERRED constraint to see how performance changes, if at all

@strk
Copy link
Contributor Author

strk commented Sep 12, 2019

Forget the last comment, it'll probably be slower to defer the check.
This PR just needs an additional commit to add the check to the tales that were created before the upgrade

@strk
Copy link
Contributor Author

strk commented Sep 12, 2019

I've pushed a commit adding the constraint to already-versioned tables.
There's no handling for tables which have an expired time earlier than creation time, so in those case the upgrade would fail.

@strk strk removed their assignment Nov 10, 2020
@@ -67,6 +67,7 @@ BEGIN
'CREATE TABLE ' || v_revision_table || '(' ||
'_revision_created INTEGER NOT NULL,' ||
'_revision_expired INTEGER,' ||
'CONSTRAINT expired_after_created CHECK ( _revision_created < _revision_expired ), ' ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need an OR _revision_expired IS NULL check?

@l0b0 l0b0 requested review from dwsilk and l0b0 December 7, 2021 00:28
Copy link
Contributor

@l0b0 l0b0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

@dwsilk dwsilk removed their request for review May 10, 2022 02:00
@l0b0 l0b0 added the automerge label Jun 1, 2022
@l0b0
Copy link
Contributor

l0b0 commented Jun 1, 2022

Closing because of no feedback. Please reopen if this can still be merged.

@l0b0 l0b0 closed this Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Forbid having _revision_expired < _revision_added in _revision tables
5 participants