{"id":7277,"date":"2019-08-22T17:42:26","date_gmt":"2019-08-23T00:42:26","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=7277"},"modified":"2025-06-13T20:19:35","modified_gmt":"2025-06-14T03:19:35","slug":"primary-uses-for-couchbase-primary-index","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/","title":{"rendered":"Primary Uses for Couchbase Primary Index"},"content":{"rendered":"<p>A couple of frequently asked questions on N1QL for query service:<\/p>\n<ol>\n<li>When do we actually use a primary index?<\/li>\n<li>Why the <a href=\"https:\/\/www.couchbase.com\/blog\/n1ql-index-advisor-improve-query-performance-and-productivity\/\">index advisor does not recommend<\/a> the primary index when that may the only choice?<\/li>\n<\/ol>\n<p>Read on&#8230;<\/p>\n<p>Couchbase is a distributed database. It supports flexible data model using JSON. Each document in a bucket will have a user-generated unique document key. This uniqueness is enforced during the inserting or updating of the data. Here\u2019s an example document.<\/p>\n<pre class=\"theme:eclipse font-size:13 wrap:true whitespace-before:2 whitespace-after:1 lang:mysql decode:true\">select meta().id, travel\r\nfrom `travel-sample` travel\r\nwhere type = 'airline' limit 1;\r\n[\r\n  {\r\n      \"id\": \"airline_10\",\r\n      \"travel\": {\r\n          \"callsign\": \"MILE-AIR\",\r\n          \"country\": \"United States\",\r\n          \"iata\": \"Q5\",\r\n          \"icao\": \"MLA\",\r\n          \"id\": 10,\r\n          \"name\": \"40-Mile Air\",\r\n          \"type\": \"airline\"\r\n          }\r\n      }\r\n  ]<\/pre>\n<pre class=\"theme:eclipse font-size:14 whitespace-before:2 lang:mysql decode:true\">INSERT INTO customer (key, value) VALUES(\u201ccx:123\u201d, {\u201cname\u201d:\u201djoe\u201d, \u201czip\u201d: 94040, \u201cstate\u201d:ca});\r\n\r\nSELECT META().id FROM customer;\r\n\r\ncx:123\r\n<\/pre>\n<p>Each Couchbase bucket can store data multiple types: customer, order, catalog, etc. When you load the \u201ctravel-sample\u201d dataset, you load five distinct types of documents: airline, airport, hotel, route, landmarks.<\/p>\n<p>But, by default, Couchbase does not have the equivalent of \u201cfull table scan\u201d to scan all the documents from start to finish.\u00a0 The primary index scan provides you the \u201cfull table scan\u201d equivalent.<\/p>\n<p>CREATE PRIMARY INDEX ix_customer_primary ON customer;<\/p>\n<p>What is the Primary Index?<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>a sorted list of all the document keys of every document type within the bucket customer.<\/li>\n<li>maintained asynchronously, just like other secondary indexes<\/li>\n<li>keeps just the document key and nothing else<\/li>\n<li>supports all the scan consistencies:\n<ul>\n<li>Unbounded<\/li>\n<li>AT_PLUS<\/li>\n<li>REQUEST_PLUS<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The primary index allows the query engine to access all the documents, then do the filtering, joining, aggregation, etc operations on them.<\/p>\n<p>EXPLAIN SELECT * from customer WHERE zip = 94040 name name = \u201cjoe\u201d and type = \u201ccx\u201d;<\/p>\n<p>This is slow. Very slow. Unnecessary document fetches; Unnecessary filtering. Wasted memory and CPU. Primary scans will retrieve ALL the documents of all types in the bucket whether or not your query eventually returns them to the user.\u00a0 While I said primary scan is like a table scan, it\u2019s much slower than your table scan since it has to scan all of the documents of all types.<\/p>\n<p><span style=\"color: #ff0000\"><strong>You should not use primary indexes.\u00a0 Do not use them.\u00a0 Especially in production.<\/strong><\/span><\/p>\n<p><strong>\u00a0<\/strong>Then why do we have primary indexes, to begin with?<\/p>\n<ol>\n<li>When you\u2019re starting to play with new sample data, you can run most queries without worrying about create specific indexes. At this point, your primary concern is to understand the data than tuning for throughput.<\/li>\n<li>When you know the range of primary keys you want to scan.\n<ol>\n<li><span class=\"theme:eclipse lang:mysql decode:true crayon-inline \">WHERE META().id between \u201ccx:123\u201d and \u201ccx:458\u201d<\/span><\/li>\n<\/ol>\n<\/li>\n<li>When you know the <strong>trailing <\/strong>META().id pattern like below\n<ol>\n<li><span class=\"theme:eclipse lang:mysql decode:true crayon-inline \">WHERE META().id LIKE \u201ccx:1%\u201d<\/span><\/li>\n<li>DO NOT use: LIKE \u201c%:123\u201d. This will result in full scan<\/li>\n<\/ol>\n<\/li>\n<li>When you do know the full META().id or list of META().id, you can use the USE KEYS to directly fetch the document without consulting the primary index\n<ol>\n<li><span class=\"theme:eclipse lang:mysql decode:true crayon-inline \">FROM customer USE KEYS [\u201ccx:123\u201d]<\/span><\/li>\n<li><span class=\"theme:eclipse lang:mysql decode:true crayon-inline \">FROM customer USE KEYS [\u201ccx:123\u201d, \u201ccx:359\u201d, \u201ccx:948\u201d]<\/span><\/li>\n<li><span class=\"theme:eclipse lang:mysql decode:true crayon-inline\">FROM customer USE KEYS (SELECT raw docid FROM mylist WHERE zip = 94501)<\/span><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h3><b>Primary Index<\/b><\/h3>\n<p><span style=\"font-weight: 400\">create the primary index on &#8216;travel-sample&#8217;;<\/span><\/p>\n<p><span style=\"font-weight: 400\">The primary index is simply the index on the document key on the whole bucket. The Couchbase data layer enforces the uniqueness constraint on the document key. The primary index, like every other index in Couchbase, is maintained asynchronously. \u00a0You set the recency of the data by setting the <\/span><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/architecture\/querying-data-with-n1ql.html\"><span style=\"font-weight: 400\">consistency level<\/span><\/a><span style=\"font-weight: 400\"> for your query.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Here is the metadata for this index:<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 whitespace-before:01 whitespace-after:1 lang:default decode:true \">select * from system:indexes where name = \u2018#primary\u2019;\r\n\"indexes\": {\r\n  \"datastore_id\": \"https:\/\/127.0.0.1:8091\",\r\n  \"id\": \"f6e3c75d6f396e7d\",\r\n  \"index_key\": [],\r\n  \"is_primary\": true,\r\n  \"keyspace_id\": \"travel-sample\",\r\n  \"name\": \"#primary\",\r\n  \"namespace_id\": \"default\",\r\n  \"state\": \"online\",\r\n  \"using\": \"gsi\"\r\n  }\r\n<\/pre>\n<p><span style=\"font-weight: 400\">The metadata gives you additional information on the index: Where the index resides (datastore_id), its state (state) and the indexing method (using).<\/span><br \/>\n<span style=\"font-weight: 400\">The primary index is used for full bucket scans (primary scans) when the query does not have any filters (predicates) or no other index or access path can be used. \u00a0\u00a0In Couchbase, you store multiple keyspaces (documents of a different type, customer, orders, inventory, etc) in a single bucket. \u00a0\u00a0So, when you do the primary scan, the query will use the index to get the document-keys and fetch all the documents in the bucket and then apply the filter. \u00a0\u00a0\u00a0So, this is VERY EXPENSIVE.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The document key design is somewhat like primary key design with multiple parts.<\/span><\/p>\n<p><span class=\"font-size:17 line-height:20 lang:mysql decode:true crayon-inline\">Lastname:firstname:customerid <\/span><\/p>\n<p><span class=\"font-size:17 line-height:20 lang:mysql decode:true crayon-inline\">Example: smith:john:X1A1849 <\/span><\/p>\n<p><span style=\"font-weight: 400\">In Couchbase, it\u2019s a best practice to prefix the key with type of the document. \u00a0Since this is a customer document, let\u2019s prefix with CX. \u00a0Now, the key becomes:<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 lang:mysql decode:true\">Example: CX:smith:john:X1A1849\r\n<\/pre>\n<p><span style=\"font-weight: 400\">So, in the same bucket, there will be other types of documents.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 lang:mysql decode:true\">ORDERS type: \u00a0OD:US:CA:294829\r\n<\/pre>\n<pre class=\"font-size:17 line-height:20 lang:mysql decode:true \">ITEMS \u00a0\u00a0\u00a0type: \u00a0\u00a0IT:KD93823\r\n<\/pre>\n<p><span style=\"font-weight: 400\">These are simply best practices. There is no restriction on the format or structure of the document key in Couchbase, except they\u2019ve to be unique within a bucket.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, if you have documents with various keys and have a primary index, you can use following queries to efficiently.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example 1: \u00a0Looking for a specific document key.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 whitespace-before:01 whitespace-after:01 lang:mysql decode:true\">SELECT * FROM  sales WHERE META().id = \u201cCX:smith:john:X1A1849\u201d;\r\n\r\n      {\r\n        \"#operator\": \"IndexScan2\",\r\n        \"index\": \"#primary\",\r\n        \"index_id\": \"4c92ab0bcca9690a\",\r\n        \"keyspace\": \"sales\",\r\n        \"namespace\": \"default\",\r\n        \"spans\": [\r\n          {\r\n            \"exact\": true,\r\n            \"range\": [\r\n              {\r\n                \"high\": \"\\\"CX:smith:john:X1A1849\\\"\",\r\n                \"inclusion\": 3,\r\n                \"low\": \"\\\"CX:smith:john:X1A1849\\\"\"\r\n              }\r\n            ]\r\n          }\r\n        ],\r\n<\/pre>\n<p><span style=\"font-weight: 400\">If you do know the full document key, you can use the following statement and avoid the index access altogether.<\/span><\/p>\n<p><span class=\"theme:dark-terminal lang:default decode:true crayon-inline \">SELECT * FROM sales USE KEYS [\u201cCX:smith:john:X1A1849\u201d] <\/span><\/p>\n<p><span style=\"font-weight: 400\">You can get more than one document in a statement.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 lang:mysql decode:true\">SELECT * FROM sales USE KEYS [\u201cCX:smith:john:X1A1849\u201d, \u201cCX:smithjr:john:X2A1492\u201d]\r\n<\/pre>\n<p><b>Example 2:<\/b><span style=\"font-weight: 400\"> \u00a0Look for a pattern. \u00a0Get ALL the customer documents.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 whitespace-before:01 whitespace-after:01 lang:mysql decode:true\">SELECT * FROM  sales WHERE META().id LIKE \u201cCX:%\u201d;\r\n      {\r\n        \"#operator\": \"IndexScan2\",\r\n        \"index\": \"#primary\",\r\n        \"index_id\": \"4c92ab0bcca9690a\",\r\n        \"keyspace\": \"sales\",\r\n        \"namespace\": \"default\",\r\n        \"spans\": [\r\n          {\r\n            \"exact\": true,\r\n            \"range\": [\r\n              {\r\n                \"high\": \"\\\"CX;\\\"\",\r\n                \"inclusion\": 1,\r\n                \"low\": \"\\\"CX:\\\"\"\r\n              }\r\n            ]\r\n          }\r\n        ],\r\n<\/pre>\n<p><b>Example 3:<\/b><span style=\"font-weight: 400\"> \u00a0Get all the customers with smith as their last name.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The following query uses the primary index efficiently, only fetching the customers with a particular range.<\/span><span style=\"font-weight: 400\"> \u00a0<\/span><b>Note:<\/b><span style=\"font-weight: 400\"> This scan is case sensitive. \u00a0To do a case insensitive scan, you\u2019ve create a secondary index with UPPER() or LOWER() of the document key.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 whitespace-before:01 whitespace-after:01 lang:mysql decode:true\">SELECT * FROM  sales WHERE META().id LIKE \"CX:smith%\";\r\n\r\n      {\r\n        \"#operator\": \"IndexScan2\",\r\n        \"index\": \"#primary\",\r\n        \"index_id\": \"4c92ab0bcca9690a\",\r\n        \"keyspace\": \"sales\",\r\n        \"namespace\": \"default\",\r\n        \"spans\": [\r\n          {\r\n            \"exact\": true,\r\n            \"range\": [\r\n              {\r\n                \"high\": \"\\\"CX:smiti\\\"\",\r\n                \"inclusion\": 1,\r\n                \"low\": \"\\\"CX:smith\\\"\"\r\n              }\r\n            ]\r\n          }\r\n        ],\r\n<\/pre>\n<p><b>Example 4:<\/b><span style=\"font-weight: 400\"> \u00a0It\u2019s common for some applications to use use email address as part of the document key since they\u2019re unique. In that case, you need to find out all of customers with gmail.com. \u00a0If this is a typical requirement, then, store the REVERSE of of the email address as the key and simply do the scan of leading string pattern.<\/span><\/p>\n<p><span class=\"font-size:17 line-height:20 lang:default decode:true crayon-inline\">Email:johnsmith@gmail.com; &amp;nbsp;&amp;nbsp;key: reverse(&#8220;johnsmith@gmail.com&#8221;) =&gt; moc.liamg@htimsnhoj\u00a0<\/span><\/p>\n<p><span class=\"font-size:17 line-height:20 lang:default decode:true crayon-inline\">Email: janesnow@yahoo.com &amp;nbsp;key: reverse(&#8220;janesnow@yahoo.com&#8221;) =&gt; moc.oohay@wonsenaj<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 whitespace-before:1 whitespace-after:1 lang:mysql decode:true\">SELECT *\r\nFROM  sales\r\nWHERE meta().id LIKE (reverse(\"@yahoo.com\") || \"%\");\r\n\r\n        \"#operator\": \"IndexScan2\",\r\n        \"index\": \"#primary\",\r\n        \"index_id\": \"4c92ab0bcca9690a\",\r\n        \"keyspace\": \"sales\",\r\n        \"namespace\": \"default\",\r\n        \"spans\": [\r\n          {\r\n            \"range\": [\r\n              {\r\n                \"high\": \"\\\"moc.oohayA\\\"\",\r\n                \"inclusion\": 1,\r\n                \"low\": \"\\\"moc.oohay@\\\"\"\r\n              }\r\n            ]\r\n          }\r\n        ],\r\n<\/pre>\n<h3><b>Named Primary Index<\/b><\/h3>\n<p><span style=\"font-weight: 400\">In Couchbase 5.0, you can create multiple replica of any index with a simple parameter to CREATE INDEX. \u00a0Following will create 3 copies of the index and there has to be minimum of 3 index nodes in the cluster.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 lang:mysql decode:true\">CREATE PRIMARY INDEX ON 'travel-sample' WITH {\"num_replica\":2}; \r\nCREATE PRIMARY INDEX `def_primary` ON `travel-sample` ;<\/pre>\n<p><span style=\"font-weight: 400\">You can also name the primary index. The rest of the features of the primary index are the same, except the index is named. A good side effect of this is that you can have multiple primary indices in Couchbase versions before 5.0 using different names. Duplicate indices help with high availability as well as query load distribution throughout them. \u00a0This is true for both primary indices and secondary indices.<\/span><\/p>\n<pre class=\"font-size:17 line-height:20 whitespace-before:1 whitespace-after:01 lang:mysql decode:true\">select meta().id as documentkey, `travel-sample` airline\r\nfrom `travel-sample`\r\nwhere type = 'airline' limit 1;\r\n{\r\n  \"airline\": {\r\n    \"callsign\": \"MILE-AIR\",\r\n    \"country\": \"United States\",\r\n    \"iata\": \"Q5\",\r\n    \"icao\": \"MLA\",\r\n    \"id\": 10,\r\n    \"name\": \"40-Mile Air\",\r\n    \"type\": \"airline\"\r\n  },\r\n  \"documentkey\": \"airline_10\"\r\n}\r\n<\/pre>\n<p>Finally, in Couchbase 6.5, we&#8217;ve introduced the Index advisor.\u00a0 It can analyze a single N1QL statement or workload.\u00a0 Read the details at:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/n1ql-index-advisor-improve-query-performance-and-productivity\/\">N1QL Index Advisor: Improve Query Performance and Productivity<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/index-advisor-for-n1ql-query-statement\/\">Index Advisor for N1QL Query Statement<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/index-advisor-for-query-workload\/\">Index Advisor For Query Workload<\/a><\/li>\n<\/ol>\n<p>This index advisor only advises suitable secondary indexes and never a primary index.\u00a0 If you&#8217;ve read the article so far, you know why! <a href=\"https:\/\/www.couchbase.com\/downloads?family=server&amp;product=couchbase-server-developer\">Download Couchbase 6.5<\/a> and Try out all the new features!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of frequently asked questions on N1QL for query service: When do we actually use a primary index? Why the index advisor does not recommend the primary index when that may the only choice? Read on&#8230; Couchbase is a [&hellip;]<\/p>\n","protected":false},"author":55,"featured_media":11848,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[9417,9381,1812],"tags":[1505,1506],"ppma_author":[8929],"class_list":["post-7277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-performance","category-indexing","category-n1ql-query","tag-index","tag-tuning"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is the Couchbase Primary Index? Learn Primary Uses<\/title>\n<meta name=\"description\" content=\"What is the Couchbase Primary Index? The primary index scan provides you with the \u201cfull table scan\u201d equivalent for all the documents from start to finish.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Primary Uses for Couchbase Primary Index\" \/>\n<meta property=\"og:description\" content=\"What is the Couchbase Primary Index? The primary index scan provides you with the \u201cfull table scan\u201d equivalent for all the documents from start to finish.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-23T00:42:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T03:19:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"882\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Keshav Murthy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rkeshavmurthy\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Keshav Murthy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\"},\"author\":{\"name\":\"Keshav Murthy\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636\"},\"headline\":\"Primary Uses for Couchbase Primary Index\",\"datePublished\":\"2019-08-23T00:42:26+00:00\",\"dateModified\":\"2025-06-14T03:19:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\"},\"wordCount\":1138,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png\",\"keywords\":[\"Index\",\"Tuning\"],\"articleSection\":[\"High Performance\",\"Indexing\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\",\"name\":\"What is the Couchbase Primary Index? Learn Primary Uses\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png\",\"datePublished\":\"2019-08-23T00:42:26+00:00\",\"dateModified\":\"2025-06-14T03:19:35+00:00\",\"description\":\"What is the Couchbase Primary Index? The primary index scan provides you with the \u201cfull table scan\u201d equivalent for all the documents from start to finish.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png\",\"width\":1200,\"height\":882},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Primary Uses for Couchbase Primary Index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636\",\"name\":\"Keshav Murthy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4e51d72fc07c662aa791316deafffac4\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g\",\"caption\":\"Keshav Murthy\"},\"description\":\"Keshav Murthy is a Vice President at Couchbase R&amp;D. Previously, he was at MapR, IBM, Informix, Sybase, with more than 20 years of experience in database design &amp; development. He lead the SQL and NoSQL R&amp;D team at IBM Informix. He has received two President's Club awards at Couchbase, two Outstanding Technical Achievement Awards at IBM. Keshav has a bachelor's degree in Computer Science and Engineering from the University of Mysore, India, holds eleven US patents and has four US patents pending.\",\"sameAs\":[\"https:\/\/blog.planetnosql.com\/\",\"https:\/\/x.com\/rkeshavmurthy\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/keshav-murthy\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is the Couchbase Primary Index? Learn Primary Uses","description":"What is the Couchbase Primary Index? The primary index scan provides you with the \u201cfull table scan\u201d equivalent for all the documents from start to finish.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/","og_locale":"en_US","og_type":"article","og_title":"Primary Uses for Couchbase Primary Index","og_description":"What is the Couchbase Primary Index? The primary index scan provides you with the \u201cfull table scan\u201d equivalent for all the documents from start to finish.","og_url":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/","og_site_name":"The Couchbase Blog","article_published_time":"2019-08-23T00:42:26+00:00","article_modified_time":"2025-06-14T03:19:35+00:00","og_image":[{"width":1200,"height":882,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png","type":"image\/png"}],"author":"Keshav Murthy","twitter_card":"summary_large_image","twitter_creator":"@rkeshavmurthy","twitter_misc":{"Written by":"Keshav Murthy","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/"},"author":{"name":"Keshav Murthy","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636"},"headline":"Primary Uses for Couchbase Primary Index","datePublished":"2019-08-23T00:42:26+00:00","dateModified":"2025-06-14T03:19:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/"},"wordCount":1138,"commentCount":2,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png","keywords":["Index","Tuning"],"articleSection":["High Performance","Indexing","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/","url":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/","name":"What is the Couchbase Primary Index? Learn Primary Uses","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png","datePublished":"2019-08-23T00:42:26+00:00","dateModified":"2025-06-14T03:19:35+00:00","description":"What is the Couchbase Primary Index? The primary index scan provides you with the \u201cfull table scan\u201d equivalent for all the documents from start to finish.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/08\/Couchbase-primary-index-gsi-global-secondary-index.png","width":1200,"height":882},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/primary-uses-for-couchbase-primary-index\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Primary Uses for Couchbase Primary Index"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c261644262bf98e146372fe647682636","name":"Keshav Murthy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4e51d72fc07c662aa791316deafffac4","url":"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g","caption":"Keshav Murthy"},"description":"Keshav Murthy is a Vice President at Couchbase R&amp;D. Previously, he was at MapR, IBM, Informix, Sybase, with more than 20 years of experience in database design &amp; development. He lead the SQL and NoSQL R&amp;D team at IBM Informix. He has received two President's Club awards at Couchbase, two Outstanding Technical Achievement Awards at IBM. Keshav has a bachelor's degree in Computer Science and Engineering from the University of Mysore, India, holds eleven US patents and has four US patents pending.","sameAs":["https:\/\/blog.planetnosql.com\/","https:\/\/x.com\/rkeshavmurthy"],"url":"https:\/\/www.couchbase.com\/blog\/author\/keshav-murthy\/"}]}},"authors":[{"term_id":8929,"user_id":55,"is_guest":0,"slug":"keshav-murthy","display_name":"Keshav Murthy","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/af74df754db27152971d0aed2f323ead5a1f9fe5afd0209af91e12e784451224?s=96&d=mm&r=g","author_category":"","last_name":"Murthy","first_name":"Keshav","job_title":"","user_url":"https:\/\/blog.planetnosql.com\/","description":"Keshav Murthy is a Vice President at Couchbase R&amp;D. Previously, he was at MapR, IBM, Informix, Sybase, with more than 20 years of experience in database design &amp; development. He lead the SQL and NoSQL R&amp;D team at IBM Informix. He has received two President's Club awards at Couchbase, two Outstanding Technical Achievement Awards at IBM. Keshav has a bachelor's degree in Computer Science and Engineering from the University of Mysore, India,  holds ten US patents and has three US patents pending."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/7277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=7277"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/7277\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/11848"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=7277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=7277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=7277"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=7277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}