Add option to filter results by namespace#17
Merged
Merged
Conversation
We now have at least two data-sets in the featureService: Who's on First
and Divipola. As such, we may want the ability to restrict results to
just features from one of the two data-sets (e.g. in a Fortis deployment
in Colombia we may want to only consider shapes from Divipola).
This change makes the assumption that we'll continue the current trend
of prefixing all ids with the data source from where they came, so if an
item has an id 1234 and came from the Who's on First dataset, we'll give
it an id like `wof-1234`. This is a reasonable pattern so it's fine to
make this assumption.
Adding a computed index on the id column lets us query the namespace with a
reasonable efficiency as the below query plan shows:
```
features=# explain analyze select id from features where lower(split_part(id,'-',1))='divipola';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on features (cost=47.06..8406.97 rows=2405 width=13) (actual time=0.977..7.781 rows=5879 loops=1)
Recheck Cond: (lower(split_part((id)::text, '-'::text, 1)) = 'divipola'::text)
Heap Blocks: exact=1236
-> Bitmap Index Scan on features_namespace_index (cost=0.00..46.46 rows=2405 width=0) (actual time=0.849..0.849 rows=5879 loops=1)
Index Cond: (lower(split_part((id)::text, '-'::text, 1)) = 'divipola'::text)
Planning time: 0.124 ms
Execution time: 8.653 ms
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We now have at least two data-sets in the featureService: Who's on First and Divipola. As such, we may want the ability to restrict results to just features from one of the two data-sets (e.g. in a Fortis deployment in Colombia we may want to only consider shapes from Divipola).
Try it live:
This change makes the assumption that we'll continue the current trend of prefixing all ids with the data source from where they came, so if an item has an id 1234 and came from the Who's on First dataset, we'll give it an id like
wof-1234. This is a reasonable pattern so it's fine to make this assumption given that it lets us avoid having to deal with migrations for now.Adding a computed index on the id column lets us query the namespace with a reasonable efficiency as the below query plan shows: