{"id":11065,"date":"2021-04-28T16:03:57","date_gmt":"2021-04-28T23:03:57","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=11065"},"modified":"2024-05-08T07:22:25","modified_gmt":"2024-05-08T14:22:25","slug":"craft-the-right-query-get-the-right-performance","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/","title":{"rendered":"Craft the Right Query, Get the Right Performance"},"content":{"rendered":"<p>There is a great blog on getting the best performance out of our Indexing service: <a href=\"https:\/\/www.couchbase.com\/blog\/create-right-index-get-right-performance\/\">&#8220;Create the Right Index, Get the Right Performance.&#8221;<\/a>, both that blog and its advice have stood the test of time. So why not have a query related blog in its namesake?<\/p>\n<p>Anyway I think the same can be said about our Query service &#8211; to get the right performance, craft the right query. The Index service can take a lot of flak for being the single contributor to query performance. But there are times where both the query and the index you&#8217;re using needs to be changed.<\/p>\n<p>Hopefully here we can show an example where it could just be a query tweak which has to happen in order to get the enterprise grade performance which Couchbase is renowned for. The following example is based on a question which was brought to us from one of our customers, so hopefully this will be helpful to a number of people using Couchbase &#8220;in anger&#8221;.<\/p>\n<h3>Your Environment<\/h3>\n<p>Let us use an example, and furthermore lets make this easy to follow, I&#8217;m a big fan of blogs which allow readers to follow along if they wish. To set the ground rules here are a few components you could use to make this example happen:<\/p>\n<ol>\n<li>The ever useful <a href=\"https:\/\/cloud.couchbase.com\/sign-up\">https:\/\/cloud.couchbase.com\/sign-up<\/a> development environment. Hanging out in your hammock on a beach in Bali? I understand, if you fire up your own Couchbase docker container, fans ablaze and there will be sand straight in your Mojito. As long as you have an Internet connection we can give you 30 minutes dev environment free of charge! Obviously you&#8217;re free to use any Couchbase environment you have already.<\/li>\n<li>The travel sample data set<\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/indexing-arrays.html\">Your handy N1QL array documentation<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/working-json-arrays-n1ql\/\">This handy pocket reference blog on working with arrays<\/a><\/li>\n<\/ol>\n<p><em><strong>N.B. The N1QL examples here will be using our scopes\/collections feature &#8211; as such the bucket context is set to the default scope in the travel-sample data set.<\/strong><\/em><\/p>\n<h4>Some Real World Context<\/h4>\n<p>To set the scene of this example we can use a common use case &#8211; marketing campaign generation. One example of this query could be to find visitors to the hotel who have left a review and liked the hotel &#8211; this data could lead to them being entitled to rewards for a loyalty program, better targeted\/similar hotel stays, or just an insight into users who are likely to leave a review\/like. All of these insights provide valuable data to better serve our hotel guests.<\/p>\n<p>The main purpose of this specific example is to show you the possibilities of querying multiple arrays within a single JSON document, and again plant the seed that sometimes you can pull even more performance out of your query service after creating the right index. Afterall, you&#8217;re making use of a system which allows for dynamic data fields and arrays are a big part of the flexibility of using JSON as a data format.<\/p>\n<h3>Humble Beginnings<\/h3>\n<p>A common way to query arrays in n1ql (as explained in the linked blog), is through the following:<\/p>\n<pre class=\"lang:default decode:true\">SELECT (ANY v IN [1, 2, 3, 4, 5] SATISFIES v &gt; 4 END) as is_found, (ANY v IN [1, 2, 3, 4, 5] SATISFIES v = 7 END) as not_found;<\/pre>\n<p>In this example we&#8217;re saying: &#8220;get me items from the array, which match the condition in the SATISFIES statement&#8221;.<\/p>\n<p>If we we&#8217;re to apply this method to our attempts to query multiple arrays in a JSON document it would likely look like the following:<\/p>\n<pre class=\"lang:default decode:true\">SELECT public_likes, reviews FROM _default WHERE type=\"hotel\"\r\nAND ANY r IN reviews SATISFIES r.author = \"Ozella Sipes\" END\r\nAND ANY l IN public_likes SATISFIES l = \"Ozella Sipes\" END LIMIT 1;<\/pre>\n<p>However this would not lead to a performant query, as N1QL currently requires you to construct a single indexable array from the arrays in the document, <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/indexing-arrays.html#array-expr\">as noted here<\/a>.<\/p>\n<h4>Creating Indexes for Multiple Array Fields<\/h4>\n<p>So how do I construct such an index I hear? Lets walk through an example, using our use case of gathering data on guests who have liked and reviewed our hotels.<\/p>\n<pre class=\"lang:default decode:true \">CREATE INDEX `reviewers_likes_idx` ON `_default`( DISTINCT ARRAY ( DISTINCT ARRAY [l,r.author]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FOR r IN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reviews\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 END)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FOR l in public_likes END) WHERE type=\"hotel\";<\/pre>\n<p>What we&#8217;re doing here is creating an index with a single array of combined likes and reviews. This is best practices and supports the note in our documentation. Just to show you a way in which you might have thought would be correct: here is the unsupported and way to definitely not index multiple array fields:<\/p>\n<pre class=\"lang:default decode:true\">CREATE INDEX `not_the_right_idx` ON `_default`( DISTINCT (ARRAY r.field FOR r in json_obj END), likes);<\/pre>\n<p><strong>This would index multiple array fields &#8211; not advised.<\/strong><\/p>\n<h4>Improving the Query<\/h4>\n<p>Below are two examples of queries which have been ran on our query workbench. Using my improved query I got my execution time down from 956.3ms to ~4ms. Try it out yourself, the improved query is at the end of this blog.<\/p>\n<h5>Non Performant Query<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-11127\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/04\/non_performant_query-1024x320.png\" alt=\"Non Performant N1QL query using Primary Index\" width=\"900\" height=\"281\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/non_performant_query-1024x320.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/non_performant_query-300x94.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/non_performant_query-768x240.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/non_performant_query-20x6.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/non_performant_query.png 1140w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h5>Improved Performant Query<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-11128\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/04\/performant_query-1024x295.png\" alt=\"Performant N1QL query using the customised multiple array index\" width=\"900\" height=\"259\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/performant_query-1024x295.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/performant_query-300x86.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/performant_query-768x221.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/performant_query-20x6.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/04\/performant_query.png 1279w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>In essence, both of our queries would work, however the times taken to execute both of the queries massively differ, and this is because we are making use of the carefully crafted and best practices index in the latter query. If you&#8217;ve followed along this far, you can run it for yourself. Be aware, I&#8217;ve added &#8220;Ozella Sipes&#8221; to be both a review Author and a public liker in one of the hotel documents to test my query works! Your results may differ depending on the name you use.<\/p>\n<pre class=\"lang:default decode:true\">SELECT META().id FROM _default WHERE type=\"hotel\"\r\nAND ANY l IN public_likes SATISFIES (\r\n\u00a0\u00a0\u00a0 ANY r IN reviews\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SATISFIES [l,r.author] = [\"Ozella Sipes\", \"Ozella Sipes\"] END) END\r\nLIMIT 1;<\/pre>\n<p>I hope this blog has been useful, and given you insight that in some cases, using the right query to get the right performance also needs to be considered!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a great blog on getting the best performance out of our Indexing service: &#8220;Create the Right Index, Get the Right Performance.&#8221;, both that blog and its advice have stood the test of time. So why not have a [&hellip;]<\/p>\n","protected":false},"author":76077,"featured_media":11030,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,8905,1812],"tags":[],"ppma_author":[9168],"class_list":["post-11065","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-couchbase-global-secondary-index","category-n1ql-query"],"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>Craft the Right Query, Get the Right Performance - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Using Couchbases N1QL language, this blog will show you how you can iteratively craft performant queries alongside your Indexes\" \/>\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\/craft-the-right-query-get-the-right-performance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Craft the Right Query, Get the Right Performance\" \/>\n<meta property=\"og:description\" content=\"Using Couchbases N1QL language, this blog will show you how you can iteratively craft performant queries alongside your Indexes\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-28T23:03:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-08T14:22:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/03\/feature-image-c.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sam Redman, Solutions Engineer\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sam Redman, Solutions Engineer\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/\"},\"author\":{\"name\":\"Sam Redman\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/512e4ed8ed1188a93cb7c3aee277f408\"},\"headline\":\"Craft the Right Query, Get the Right Performance\",\"datePublished\":\"2021-04-28T23:03:57+00:00\",\"dateModified\":\"2024-05-08T14:22:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/\"},\"wordCount\":886,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg\",\"articleSection\":[\"Best Practices and Tutorials\",\"Couchbase Global Secondary Index\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/\",\"name\":\"Craft the Right Query, Get the Right Performance - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg\",\"datePublished\":\"2021-04-28T23:03:57+00:00\",\"dateModified\":\"2024-05-08T14:22:25+00:00\",\"description\":\"Using Couchbases N1QL language, this blog will show you how you can iteratively craft performant queries alongside your Indexes\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg\",\"width\":1200,\"height\":628,\"caption\":\"Introduction to Ottoman\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Craft the Right Query, Get the Right Performance\"}]},{\"@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\/512e4ed8ed1188a93cb7c3aee277f408\",\"name\":\"Sam Redman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/69dc9b1e46ceb237d29e1e4b626c6bcc\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ee34f7b9f2c46328736cdab03babdfd5ddc97cdd4a12ddd4b1b2d0f455eba51d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ee34f7b9f2c46328736cdab03babdfd5ddc97cdd4a12ddd4b1b2d0f455eba51d?s=96&d=mm&r=g\",\"caption\":\"Sam Redman\"},\"description\":\"Solutions Engineer at Couchbase. Sam has previously as a developer and an SRE before joining Couchbase.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/sam-redman\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Craft the Right Query, Get the Right Performance - The Couchbase Blog","description":"Using Couchbases N1QL language, this blog will show you how you can iteratively craft performant queries alongside your Indexes","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\/craft-the-right-query-get-the-right-performance\/","og_locale":"en_US","og_type":"article","og_title":"Craft the Right Query, Get the Right Performance","og_description":"Using Couchbases N1QL language, this blog will show you how you can iteratively craft performant queries alongside your Indexes","og_url":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-04-28T23:03:57+00:00","article_modified_time":"2024-05-08T14:22:25+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/03\/feature-image-c.jpg","type":"image\/jpeg"}],"author":"Sam Redman, Solutions Engineer","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sam Redman, Solutions Engineer","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/"},"author":{"name":"Sam Redman","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/512e4ed8ed1188a93cb7c3aee277f408"},"headline":"Craft the Right Query, Get the Right Performance","datePublished":"2021-04-28T23:03:57+00:00","dateModified":"2024-05-08T14:22:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/"},"wordCount":886,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg","articleSection":["Best Practices and Tutorials","Couchbase Global Secondary Index","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/","url":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/","name":"Craft the Right Query, Get the Right Performance - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg","datePublished":"2021-04-28T23:03:57+00:00","dateModified":"2024-05-08T14:22:25+00:00","description":"Using Couchbases N1QL language, this blog will show you how you can iteratively craft performant queries alongside your Indexes","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/03\/feature-image-c.jpg","width":1200,"height":628,"caption":"Introduction to Ottoman"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/craft-the-right-query-get-the-right-performance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Craft the Right Query, Get the Right Performance"}]},{"@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\/512e4ed8ed1188a93cb7c3aee277f408","name":"Sam Redman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/69dc9b1e46ceb237d29e1e4b626c6bcc","url":"https:\/\/secure.gravatar.com\/avatar\/ee34f7b9f2c46328736cdab03babdfd5ddc97cdd4a12ddd4b1b2d0f455eba51d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ee34f7b9f2c46328736cdab03babdfd5ddc97cdd4a12ddd4b1b2d0f455eba51d?s=96&d=mm&r=g","caption":"Sam Redman"},"description":"Solutions Engineer at Couchbase. Sam has previously as a developer and an SRE before joining Couchbase.","url":"https:\/\/www.couchbase.com\/blog\/author\/sam-redman\/"}]}},"authors":[{"term_id":9168,"user_id":76077,"is_guest":0,"slug":"sam-redman","display_name":"Sam Redman, Solutions Engineer","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/ee34f7b9f2c46328736cdab03babdfd5ddc97cdd4a12ddd4b1b2d0f455eba51d?s=96&d=mm&r=g","author_category":"","last_name":"Redman","first_name":"Sam","job_title":"","user_url":"","description":"Sam Redman is a Solutions Engineer at Couchbase. Sam previously worked in development and SRE environments before joining Couchbase."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/11065","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\/76077"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=11065"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/11065\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/11030"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=11065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=11065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=11065"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=11065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}