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

Add option to filter results by namespace #17

Merged
merged 1 commit into from Sep 7, 2017

Conversation

Projects
None yet
2 participants
@c-w
Copy link
Member

commented Sep 7, 2017

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:

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
Add option to filter results by namespace
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
```

@c-w c-w requested review from jcjimenez and erikschlegel Sep 7, 2017

@jcjimenez
Copy link
Contributor

left a comment

LGTM

@c-w c-w merged commit e6fc2e7 into master Sep 7, 2017

@c-w c-w deleted the filter-namespace branch Sep 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.