Skip to content

Removed usage of pattern matching in PostgreSQL when not necessary (ref #970, fixes #974)#975

Merged
leplatrem merged 8 commits intomasterfrom
974-use-pattern-matching-only-if-necessary
Dec 9, 2016
Merged

Removed usage of pattern matching in PostgreSQL when not necessary (ref #970, fixes #974)#975
leplatrem merged 8 commits intomasterfrom
974-use-pattern-matching-only-if-necessary

Conversation

@leplatrem
Copy link
Contributor

@leplatrem leplatrem commented Dec 2, 2016

Ref #970, Fixes #974

r? @Natim

Note: this is a huge performance win.

DELETE FROM access_control_entries
USING object_ids
WHERE object_id ~ column1;"""
WHERE object_id LIKE column1;"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: according to docs (and performance obtained locally), LIKE behaves exactly like = if the values do not contain % character

@leplatrem leplatrem changed the title Removed usage of pattern matching in PostgreSQL when not necessary (ref #907, fixes #974) Removed usage of pattern matching in PostgreSQL when not necessary (ref #970, fixes #974) Dec 2, 2016
@leplatrem
Copy link
Contributor Author

We could stick to LIKE and have more perf gain:

[dbname] # SELECT COUNT(*) FROM access_control_entries WHERE object_id SIMILAR TO '/buckets/[a-zA-Z\-_]+';
 count 
-------
     6
(1 row)

Time: 30,519 ms
[dbname] # SELECT COUNT(*) FROM access_control_entries WHERE object_id LIKE '/buckets/%' AND object_id NOT LIKE '/buckets/%/%';
 count 
-------
     6
(1 row)

Time: 4,435 ms

@leplatrem leplatrem force-pushed the 974-use-pattern-matching-only-if-necessary branch from be8a35a to 1f3f85d Compare December 9, 2016 19:32
@leplatrem leplatrem merged commit c1a9a72 into master Dec 9, 2016
@leplatrem leplatrem deleted the 974-use-pattern-matching-only-if-necessary branch December 9, 2016 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants