{"id":7072,"date":"2023-04-14T00:00:00","date_gmt":"2023-04-14T04:00:00","guid":{"rendered":"https:\/\/www.sisense.com\/use-subqueries-to-count-distinct-50x-faster\/"},"modified":"2024-10-11T08:25:09","modified_gmt":"2024-10-11T12:25:09","slug":"use-subqueries-to-count-distinct-50x-faster","status":"publish","type":"post","link":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/","title":{"rendered":"Use subqueries to count distinct 50X faster"},"content":{"rendered":"<p><em>NB: These techniques are universal, but for syntax we chose Postgres. Thanks to the inimitable <\/em><a href=\"https:\/\/www.pgadmin.org\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"(opens in a new tab)\"><em>pgAdminIII<\/em><\/a><em> for the Explain graphics.<\/em><\/p>\r\n<h2>So useful, yet so slow<\/h2>\r\n<p>Count distinct is the bane of SQL analysts, so it was an obvious choice for our first blog post.<\/p>\r\n<p>First thing first: If you have a huge dataset and can tolerate some imprecision, a probabilistic counter like HyperLogLog can be your best bet.\u00a0For a quick, precise answer, some simple subqueries can save you a lot of time.<\/p>\r\n<p>Let\u2019s start with a simple query we run all the time: Which dashboards do most users visit?<\/p>\r\n<pre class=\"wp-block-code\"><code>select \r\n  dashboards.name, \r\n  count(distinct time_on_site_logs.user_id)\r\nfrom time_on_site_logs \r\njoin dashboards on time_on_site_logs.dashboard_id = dashboards.id\r\ngroup by name \r\norder by count desc<\/code><\/pre>\r\n<p>This returns a graph like this:<\/p>\r\n<figure class=\"wp-block-image fancybox\"><img decoding=\"async\" class=\"wp-image-76193\" src=\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/Dashboards-by-Distinct.png\" alt=\"Dashboards by Distinct\" \/><\/figure>\r\n<p>For starters, let\u2019s assume the handy indices on user_id and dashboard_id are in place, and there are lots more log lines than dashboards and users.<\/p>\r\n<p>On just 10 million rows, this query takes <strong>48 seconds<\/strong>. To understand why, let\u2019s consult our handy SQL explain:<\/p>\r\n<figure class=\"wp-block-image fancybox\"><img decoding=\"async\" class=\"wp-image-76188\" src=\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/48-seconds-map.png\" alt=\"48 seconds\" \/><\/figure>\r\n<p>It\u2019s slow because the database is iterating over all the logs and all the dashboards, then joining them, then sorting them, all before getting down to real work of grouping and aggregating.<\/p>\r\n<p><strong>Become an instant SQL expert:<\/strong><\/p>\r\n<p><a class=\"action-btn \" href=\"https:\/\/www.sisense.com\/resources\/whitepapers\/\" target=\"_blank\" rel=\"noopener noreferrer\">Get the Starter Kit<\/a><\/p>\r\n<h2>Aggregate, then join<\/h2>\r\n<p>Anything after the group-and-aggregate is going to be a lot cheaper because the data size is much smaller. Since we don\u2019t need dashboards.name in the group-and-aggregate, we can have the database do the aggregation first, before the join:<\/p>\r\n<pre class=\"wp-block-code\"><code>select\r\n  dashboards.name,\r\n  log_counts.ct\r\nfrom dashboards\r\njoin (\r\n  select\r\n    dashboard_id,\r\n    count(distinct user_id) as ct\r\n  from time_on_site_logs \r\n  group by dashboard_id\r\n) as log_counts \r\non log_counts.dashboard_id = dashboards.id\r\norder by log_counts.ct desc<\/code><\/pre>\r\n<p>This query runs in <strong>20 seconds<\/strong>, a <strong>2.4X<\/strong> improvement! Once again, our trusty explain will show us why:<\/p>\r\n<figure class=\"wp-block-image fancybox\"><img decoding=\"async\" class=\"wp-image-76183\" src=\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/20-seconds-map.png\" alt=\"20 seconds map\" \/><\/figure>\r\n<p>As promised, our group-and-aggregate comes before the join. And, as a bonus, we can take advantage of the index on the time_on_site_logs table.<\/p>\r\n<h2>First, reduce the dataset<\/h2>\r\n<p>We can do better. By doing the group-and-aggregate over the whole logs table, we made our database process a lot of data unnecessarily. Count distinct builds a hash set for each group \u2014 in this case, each dashboard_id \u2014 to keep track of which values have been seen in which buckets.<\/p>\r\n<p>Instead of doing all that work, we can compute the distincts in advance, which only needs one hash set. Then we do a simple aggregation over all of them.<\/p>\r\n<pre class=\"wp-block-code\"><code>select\r\n  dashboards.name,\r\n  log_counts.ct\r\nfrom dashboards \r\njoin (\r\n  select distinct_logs.dashboard_id, \r\n  count(1) as ct\r\n  from (\r\n    select distinct dashboard_id, user_id\r\n    from time_on_site_logs\r\n  ) as distinct_logs\r\n  group by distinct_logs.dashboard_id\r\n) as log_counts \r\non log_counts.dashboard_id = dashboards.id\r\norder by log_counts.ct desc<\/code><\/pre>\r\n<p>We\u2019ve taken the inner count-distinct-and-group and broken it up into two pieces. The inner piece computes distinct (dashboard_id, user_id) pairs. The second piece runs a simple, speedy group-and-count over them. As always, the join is last.<\/p>\r\n<figure class=\"wp-block-image fancybox\"><img decoding=\"async\" class=\"wp-image-76198\" src=\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/7_10-seconds-map.png\" alt=\"7-10 seconds map\" \/><\/figure>\r\n<p>And now for the big reveal: This sucker takes <strong>0.7 seconds<\/strong>! That\u2019s a <strong>28X<\/strong> increase over the previous query, and a <strong>68X<\/strong> increase over the original query.<\/p>\r\n<p>As always, data size and shape matters a lot. These examples benefit a lot from a relatively low cardinality. There are a small number of distinct (user_id, dashboard_id) pairs compared to the total amount of data. The more unique pairs there are \u2014 the more data rows are unique snowflakes that must be grouped and counted \u2014 the less free lunch there will be.<\/p>\r\n<p>Next time count distinct is taking all day, try a few subqueries to lighten the load.<\/p>\r\n<p><strong>Become an instant SQL expert:<\/strong><\/p>\r\n<p><a class=\"action-btn \" href=\"https:\/\/www.sisense.com\/resources\/whitepapers\/\" target=\"_blank\" rel=\"noopener noreferrer\">Get the Starter Kit<\/a><\/p>\r\n<p><!-- \/wp:paragraph -->\r\n\r\n<!-- wp:heading \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:code \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:image {\"id\":76193,\"className\":\"fancybox\"} \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:image {\"id\":76188,\"className\":\"fancybox\"} \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:sisense\/link-button {\"text\":\"Get the Starter Kit\",\"target\":\"_blank\"} \/-->\r\n\r\n<!-- wp:heading \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:code \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:image {\"id\":76183,\"className\":\"fancybox\"} \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:heading \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:code \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:image {\"id\":76198,\"className\":\"fancybox\"} \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:paragraph \/-->\r\n\r\n<!-- wp:heading \/-->\r\n\r\n<!-- wp:sisense\/link-button {\"text\":\"Get the Starter Kit\",\"target\":\"_blank\"} \/--><\/p>","protected":false},"excerpt":{"rendered":"<p>NB: These techniques are universal, but for syntax we chose Postgres. Thanks to the inimitable pgAdminIII for the Explain graphics. So useful, yet so slow Count distinct is the bane of SQL analysts, so it was an obvious choice for&#8230;<\/p>\n","protected":false},"author":4,"featured_media":7259,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_searchwp_excluded":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[44],"tags":[472],"application":[10],"buyer-role":[],"buyer-stage":[],"department":[],"industry":[],"topic":[],"class_list":["post-7072","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech-talk","tag-data-team","application-cloud-data-teams"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.5 (Yoast SEO v23.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Use Subqueries to Count Distinct 50X Faster | Sisense<\/title>\n<meta name=\"description\" content=\"Count distinct is the bane of SQL analysts. Next time count distinct is taking all day, try a few subqueries to lighten the load.\" \/>\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.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use subqueries to count distinct 50X faster\" \/>\n<meta property=\"og:description\" content=\"NB: These techniques are universal, but for syntax we chose Postgres. Thanks to the inimitable pgAdminIII for the Explain graphics. So useful, yet so slow\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\" \/>\n<meta property=\"og:site_name\" content=\"Sisense\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-14T04:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-11T12:25:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/pd-blog-yoast-use-subqueries-to-count-50x-min.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=\"Sisense Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/pd-blog-yoast-use-subqueries-to-count-50x-min.jpg\" \/>\n<meta name=\"twitter:creator\" content=\"@sisense\" \/>\n<meta name=\"twitter:site\" content=\"@sisense\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sisense Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\"},\"author\":{\"name\":\"Sisense Team\",\"@id\":\"https:\/\/www.sisense.com\/#\/schema\/person\/e70aa3a7bbc471e4b7b8c5a7d2b36115\"},\"headline\":\"Use subqueries to count distinct 50X faster\",\"datePublished\":\"2023-04-14T04:00:00+00:00\",\"dateModified\":\"2024-10-11T12:25:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\"},\"wordCount\":526,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.sisense.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg\",\"keywords\":[\"data team\"],\"articleSection\":[\"Tech Talk\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\",\"url\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\",\"name\":\"Use Subqueries to Count Distinct 50X Faster | Sisense\",\"isPartOf\":{\"@id\":\"https:\/\/www.sisense.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg\",\"datePublished\":\"2023-04-14T04:00:00+00:00\",\"dateModified\":\"2024-10-11T12:25:09+00:00\",\"description\":\"Count distinct is the bane of SQL analysts. Next time count distinct is taking all day, try a few subqueries to lighten the load.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage\",\"url\":\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg\",\"contentUrl\":\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg\",\"width\":1200,\"height\":628,\"caption\":\"pd blog featured use subqueries to count 50x min\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sisense.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use subqueries to count distinct 50X faster\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sisense.com\/#website\",\"url\":\"https:\/\/www.sisense.com\/\",\"name\":\"Sisense\",\"description\":\"Build your business with anywhere-analytics\",\"publisher\":{\"@id\":\"https:\/\/www.sisense.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sisense.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.sisense.com\/#organization\",\"name\":\"Sisense\",\"url\":\"https:\/\/www.sisense.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sisense.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/sisense-yoast-og.jpg\",\"contentUrl\":\"https:\/\/cdn.sisense.com\/wp-content\/uploads\/sisense-yoast-og.jpg\",\"width\":1200,\"height\":600,\"caption\":\"Sisense\"},\"image\":{\"@id\":\"https:\/\/www.sisense.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/sisense\",\"https:\/\/www.linkedin.com\/company\/sisense\",\"https:\/\/github.com\/sisense\/\"],\"description\":\"Sisense accelerates product innovation through AI\/ML capabilities. Our global analytics platform lets customers drive better, faster decisions for their business and end users.\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sisense.com\/#\/schema\/person\/e70aa3a7bbc471e4b7b8c5a7d2b36115\",\"name\":\"Sisense Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sisense.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/213e415f47bc3c7f0155a0755b1cea8c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/213e415f47bc3c7f0155a0755b1cea8c?s=96&d=mm&r=g\",\"caption\":\"Sisense Team\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Use Subqueries to Count Distinct 50X Faster | Sisense","description":"Count distinct is the bane of SQL analysts. Next time count distinct is taking all day, try a few subqueries to lighten the load.","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.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/","og_locale":"en_US","og_type":"article","og_title":"Use subqueries to count distinct 50X faster","og_description":"NB: These techniques are universal, but for syntax we chose Postgres. Thanks to the inimitable pgAdminIII for the Explain graphics. So useful, yet so slow","og_url":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/","og_site_name":"Sisense","article_published_time":"2023-04-14T04:00:00+00:00","article_modified_time":"2024-10-11T12:25:09+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/pd-blog-yoast-use-subqueries-to-count-50x-min.jpg","type":"image\/jpeg"}],"author":"Sisense Team","twitter_card":"summary_large_image","twitter_image":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/pd-blog-yoast-use-subqueries-to-count-50x-min.jpg","twitter_creator":"@sisense","twitter_site":"@sisense","twitter_misc":{"Written by":"Sisense Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#article","isPartOf":{"@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/"},"author":{"name":"Sisense Team","@id":"https:\/\/www.sisense.com\/#\/schema\/person\/e70aa3a7bbc471e4b7b8c5a7d2b36115"},"headline":"Use subqueries to count distinct 50X faster","datePublished":"2023-04-14T04:00:00+00:00","dateModified":"2024-10-11T12:25:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/"},"wordCount":526,"commentCount":0,"publisher":{"@id":"https:\/\/www.sisense.com\/#organization"},"image":{"@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg","keywords":["data team"],"articleSection":["Tech Talk"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/","url":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/","name":"Use Subqueries to Count Distinct 50X Faster | Sisense","isPartOf":{"@id":"https:\/\/www.sisense.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage"},"image":{"@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg","datePublished":"2023-04-14T04:00:00+00:00","dateModified":"2024-10-11T12:25:09+00:00","description":"Count distinct is the bane of SQL analysts. Next time count distinct is taking all day, try a few subqueries to lighten the load.","breadcrumb":{"@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#primaryimage","url":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg","contentUrl":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/2014\/04\/10162019\/pd-blog-featured-use-subqueries-to-count-50x-min.jpg","width":1200,"height":628,"caption":"pd blog featured use subqueries to count 50x min"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sisense.com\/blog\/use-subqueries-to-count-distinct-50x-faster\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sisense.com\/"},{"@type":"ListItem","position":2,"name":"Use subqueries to count distinct 50X faster"}]},{"@type":"WebSite","@id":"https:\/\/www.sisense.com\/#website","url":"https:\/\/www.sisense.com\/","name":"Sisense","description":"Build your business with anywhere-analytics","publisher":{"@id":"https:\/\/www.sisense.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sisense.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.sisense.com\/#organization","name":"Sisense","url":"https:\/\/www.sisense.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sisense.com\/#\/schema\/logo\/image\/","url":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/sisense-yoast-og.jpg","contentUrl":"https:\/\/cdn.sisense.com\/wp-content\/uploads\/sisense-yoast-og.jpg","width":1200,"height":600,"caption":"Sisense"},"image":{"@id":"https:\/\/www.sisense.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/sisense","https:\/\/www.linkedin.com\/company\/sisense","https:\/\/github.com\/sisense\/"],"description":"Sisense accelerates product innovation through AI\/ML capabilities. Our global analytics platform lets customers drive better, faster decisions for their business and end users."},{"@type":"Person","@id":"https:\/\/www.sisense.com\/#\/schema\/person\/e70aa3a7bbc471e4b7b8c5a7d2b36115","name":"Sisense Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sisense.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/213e415f47bc3c7f0155a0755b1cea8c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/213e415f47bc3c7f0155a0755b1cea8c?s=96&d=mm&r=g","caption":"Sisense Team"}}]}},"_links":{"self":[{"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/posts\/7072"}],"collection":[{"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/comments?post=7072"}],"version-history":[{"count":1,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/posts\/7072\/revisions"}],"predecessor-version":[{"id":22794,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/posts\/7072\/revisions\/22794"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/media\/7259"}],"wp:attachment":[{"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/media?parent=7072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/categories?post=7072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/tags?post=7072"},{"taxonomy":"application","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/application?post=7072"},{"taxonomy":"buyer-role","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/buyer-role?post=7072"},{"taxonomy":"buyer-stage","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/buyer-stage?post=7072"},{"taxonomy":"department","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/department?post=7072"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/industry?post=7072"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.sisense.com\/wp-json\/wp\/v2\/topic?post=7072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}