From c67ae71dda8319061c9fb0df7ce80d5707c104f4 Mon Sep 17 00:00:00 2001 From: csobier Date: Thu, 25 Aug 2016 14:51:08 -0400 Subject: [PATCH] added create indexes to sql api docs --- doc/query_optimizations.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/query_optimizations.md b/doc/query_optimizations.md index 0448b480..7517d2e7 100644 --- a/doc/query_optimizations.md +++ b/doc/query_optimizations.md @@ -2,7 +2,25 @@ There are some tricks to consider when using the SQL API that might make your application a little faster. -* Only request the fields you need. Selecting all columns will return a full version of your geometry in *the_geom*, as well as a reprojected version in *the_geom_webmercator*. -* Use PostGIS functions to simplify and filter out unneeded geometries when possible. One very handy function is, [ST_Simplify](http://www.postgis.org/docs/ST_Simplify.html). -* Remember to build indexes that will speed up some of your more common queries. For details, see [Creating Indexes](http://docs.carto.com/carto-editor/managing-your-data/#creating-indexes) -* Use *cartodb_id* to retrieve specific rows of your data, this is the unique key column added to every CARTO table. For a sample use case, view the [_Faster data updates with Carto_](https://blog.carto.com/faster-data-updates-with-carto/) blogpost. \ No newline at end of file +* Only request the fields you need. Selecting all columns will return a full version of your geometry in *the_geom*, as well as a reprojected version in *the_geom_webmercator* +* Use PostGIS functions to simplify and filter out unneeded geometries when possible. One very handy function is, [ST_Simplify](http://www.postgis.org/docs/ST_Simplify.html) +* Remember to build indexes that will speed up some of your more common queries. For details, see [Creating Indexes](#creating-indexes) +* Use *cartodb_id* to retrieve specific rows of your data, this is the unique key column added to every CARTO table. For a sample use case, view the [_Faster data updates with CARTO](https://carto.com/blog/faster-data-updates-with-cartodb/) blogpost + +## Creating Indexes + +In order to better improve map performance, advanced users can use the SQL API to add custom indexes to their data. Creating indexes is useful if you have a large dataset with filtered data. By indexing select data, you are improving the performance of the map and generating the results faster. The index functionality is useful in the following scenarios: + +- If you are filtering a dataset by values in one or a more columns +- If you are regularly querying data through the SQL API, and filtering by one or a more columns +- If you are creating Torque maps on very large datasets. Since Torque maps are based on time-sensitive data (i.e. a date or numeric column), creating an index on the time data is optimal + +Indexed data is typically a single column representing filtered data. To create a single column index, apply this SQL query to your dataset: + +{% highlight bash %} +CREATE INDEX idx_{DATASET NAME}_{COLUMN_NAME} ON {DATASET_NAME} ({COLUMN_NAME}) +{% endhighlight %} + +**Tip:** You can also apply more advanced, multi-column indexes. Please review the full documentation about [PostgreSQL Indexes](http://www.postgresql.org/docs/9.1/static/sql-createindex.html) before proceeding. + +**Note:** Indexes are allocated towards the amount of data storage associated with your account. Be mindful when creating custom indexes. Note that indexes automatically generated by CARTO are _not_ counted against your quota. For example, `the_geom` and `cartodb_id` columns. These columns are used to index geometries for your dataset and are not associated with storage.