Using `original_sql` and `rollup` pre-aggregations effectively
Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.
Use case
You can use the sql parameter to define cubes
over arbitrary SQL queries. Sometimes, these queries might be fairly complex
and take substantial time to execute. That’s totally okay because you can use
pre-aggregations to accelerate queries to such cubes.However, if you have more than one pre-aggregation that references members of
such a cube, its sql expression would have to be executed each time every
pre-aggregation is built. This also the case if you run both pre-aggregated
and non-pre-aggregated queries against such a cube.A special original_sql pre-aggregation
can help:
First, it will materialize the results of the sql expression in the data source.
Then, it will make these results available to other rollup pre-aggregations
and non-pre-aggregated queries.
Configuration
We can do this by creating a pre-aggregation of type
original_sql on the data source
database, and then configuring our existing rollup
pre-aggregations to use the original_sql pre-aggregation with the
use_original_sql_pre_aggregations property.
Storing pre-aggregations on an internal database requires write-access. Please
ensure that your database driver is not configured with readOnly: true.
cubes: - name: orders sql: "<YOUR_EXPENSIVE_SQL_QUERY HERE>" pre_aggregations: - name: base type: original_sql external: false - name: main dimensions: - id - name measures: - count time_dimension: created_at granularity: day use_original_sql_pre_aggregations: true
With the above data model, the main pre-aggregation is built from the base
pre-aggregation.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Cube Documentation","colors":{"primary":"#5339CF","light":"#A5A3FF","dark":"#716EEE"},"logo":{"light":"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/logo/light.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=8bbf45ba64eac6116629064fac55aad7","dark":"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/logo/dark.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=d8fa230950c8c63b3c2f88d2768694d0"},"favicon":"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/favicon.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=3b0cb7aa770d2abd546ef19463fbba8c","navbar":{"links":[{"href":"https://cube.dev/demos","label":"Demos"},{"href":"https://cube.dev/changelog","label":"Changelog"},{"href":"https://slack.cube.dev","label":"Community"}],"primary":{"type":"button","label":"Get Started","href":"https://cubecloud.dev/auth/signup"}},"footer":{"socials":{"x":"https://x.com/the_cube_dev","github":"https://github.com/cube-js/cube","linkedin":"https://www.linkedin.com/company/cube-dev"},"links":[{"header":"Legal","items":[{"label":"Privacy Policy","href":"https://cube.dev/legal/privacy-policy"},{"label":"Cookie Preferences","href":"#cookie-preferences"}]}]},"seo":{"metatags":{"og:type":"website","og:site_name":"Cube Documentation"},"indexing":"navigable"},"icons":{"library":"tabler"},"styling":{"codeblocks":"dark","latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"cubed3","hasAudioNarration":false,"actualSubdomain":"cubed3","customDomains":["docs.cube.dev"],"gitSource":{"type":"github","owner":"cube-js","repo":"cube","deployBranch":"master","contentDirectory":"docs-mintlify","isPrivate":true,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6aff77fbb5f9972b85a20c09","clientVersion":"0.0.4227","searchFilterCounts":[{"language":"default","tag":"API","count":238},{"language":"default","tag":"Platform Endpoints","count":231},{"language":"default","tag":"Documentation","count":101},{"language":"default","tag":"Admin","count":95},{"language":"default","tag":"Data Modeling","count":65},{"language":"default","tag":"Recipes","count":47},{"language":"default","tag":"Topics","count":47},{"language":"default","tag":"Reference","count":44},{"language":"default","tag":"Connect to data","count":31},{"language":"default","tag":"Explore \u0026 Analyze","count":30}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#content-area table,.mdx-content table{width:100%!important}.cube-consent{position:fixed;right:16px;bottom:16px;z-index:2147483000;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;width:min(440px, calc(100vw - 32px));padding:16px;background:#fff;color:#111827;border:1px solid #e5e7eb;border-radius:8px;box-shadow:0 8px 24px rgb(0 0 0 / 12%);font-size:14px;line-height:1.5}html.dark .cube-consent{background:#111318;color:#f3f4f6;border-color:#2b2f38}.cube-consent__title{margin:0;padding-right:24px;font-size:16px;font-weight:600}.cube-consent__text,.cube-consent__status{margin:0;color:#4b5563}html.dark .cube-consent__text,html.dark .cube-consent__status{color:#b6bcc8}.cube-consent__link{color:inherit;text-decoration:underline}.cube-consent__actions{display:flex;gap:8px}.cube-consent__button{flex:1;padding:8px 16px;border:1px solid #111827;border-radius:6px;background:#111827;color:#fff;font:inherit;font-weight:500;cursor:pointer}html.dark .cube-consent__button{border-color:#f3f4f6;background:#f3f4f6;color:#111318}.cube-consent__button:hover{opacity:0.88}.cube-consent__button:focus-visible,.cube-consent__close:focus-visible,.cube-consent__link:focus-visible{outline:2px solid #111827;outline-offset:2px}html.dark .cube-consent :focus-visible{outline-color:#f3f4f6}.cube-consent__close{position:absolute;top:8px;right:8px;width:24px;height:24px;padding:0;border:0;background:transparent;color:inherit;font-size:20px;line-height:1;cursor:pointer}"}]}
{"page":{"pagePath":"recipes/pre-aggregations/using-originalsql-and-rollups-effectively","slug":"/recipes/pre-aggregations/using-originalsql-and-rollups-effectively","pageMetadata":{"title":"Using `original_sql` and `rollup` pre-aggregations effectively","description":"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.","href":"/recipes/pre-aggregations/using-originalsql-and-rollups-effectively"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,CodeGroup,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`use-case`,children:`Use case`}),`\n`,_jsxs(_components.p,{children:[`You can use the `,_jsxs(_components.a,{href:`/reference/data-modeling/cube#sql`,children:[_jsx(_components.code,{children:`sql`}),` parameter`]}),` to define `,_jsx(_components.a,{href:`/reference/data-modeling/cube`,children:`cubes`}),`\nover arbitrary SQL queries. Sometimes, these queries might be fairly complex\nand take substantial time to execute. That’s totally okay because you can use\n`,_jsx(_components.a,{href:`/docs/pre-aggregations/using-pre-aggregations`,children:`pre-aggregations`}),` to accelerate queries to such cubes.`]}),`\n`,_jsxs(_components.p,{children:[`However, if you have more than one pre-aggregation that references members of\nsuch a cube, its `,_jsx(_components.code,{children:`sql`}),` expression would have to be executed each time every\npre-aggregation is built. This also the case if you run both pre-aggregated\nand non-pre-aggregated queries against such a cube.`]}),`\n`,_jsxs(_components.p,{children:[`A special `,_jsxs(_components.a,{href:`/reference/data-modeling/pre-aggregations#original_sql`,children:[_jsx(_components.code,{children:`original_sql`}),` pre-aggregation`]}),`\ncan help:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`First, it will materialize the results of the `,_jsx(_components.code,{children:`sql`}),` expression in the data source.`]}),`\n`,_jsxs(_components.li,{children:[`Then, it will make these results available to other `,_jsx(_components.code,{children:`rollup`}),` pre-aggregations\nand non-pre-aggregated queries.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`configuration`,children:`Configuration`}),`\n`,_jsxs(_components.p,{children:[`We can do this by creating a pre-aggregation of type\n`,_jsx(_components.a,{href:`/reference/data-modeling/pre-aggregations#original_sql`,children:_jsx(_components.code,{children:`original_sql`})}),` on the data source\ndatabase, and then configuring our existing `,_jsx(_components.code,{children:`rollup`}),`\npre-aggregations to use the `,_jsx(_components.code,{children:`original_sql`}),` pre-aggregation with the\n`,_jsxs(_components.a,{href:`/reference/data-modeling/pre-aggregations#use_original_sql_pre_aggregations`,children:[_jsx(_components.code,{children:`use_original_sql_pre_aggregations`}),` property`]}),`.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Storing pre-aggregations on an internal database requires write-access. Please\nensure that your database driver is not configured with `,_jsx(_components.code,{children:`readOnly: true`}),`.`]})}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`YAML`,numberOfLines:`18`,language:`yaml`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`yaml`,children:_jsxs(_components.code,{language:`yaml`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`cubes`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`name`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`orders`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` sql`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"\u003cYOUR_EXPENSIVE_SQL_QUERY HERE>\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` pre_aggregations`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`name`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`base`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` type`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`original_sql`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` external`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`false`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`name`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`main`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` dimensions`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`id`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`name`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` measures`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`count`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` time_dimension`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`created_at`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` granularity`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`day`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` use_original_sql_pre_aggregations`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`true`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`JavaScript`,numberOfLines:`18`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`cube`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"orders\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` sql:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `\u003cYOUR_EXPENSIVE_SQL_QUERY HERE>`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` pre_aggregations:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` base:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` type:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `original_sql`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` external:`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` false`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` main:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` dimensions:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` [`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`id`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` measures:`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` [`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`count`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` time_dimension:`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` created_at`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` granularity:`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:\" `day`\"}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` use_original_sql_pre_aggregations:`}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:` true`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`]})})})]}),`\n`,_jsx(Heading,{level:`2`,id:`result`,children:`Result`}),`\n`,_jsxs(_components.p,{children:[`With the above data model, the `,_jsx(_components.code,{children:`main`}),` pre-aggregation is built from the `,_jsx(_components.code,{children:`base`}),`\npre-aggregation.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":"dark","config":{},"pageMetadata":{"title":"Using `original_sql` and `rollup` pre-aggregations effectively","description":"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.","href":"/recipes/pre-aggregations/using-originalsql-and-rollups-effectively"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Use case","slug":"use-case","depth":2,"children":[]},{"title":"Configuration","slug":"configuration","depth":2,"children":[]},{"title":"Result","slug":"result","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/cubed3/73c42f6b43b9b3b0/scripts/extract-chat.js","/_mintlify/custom/cubed3/08d502537a7bd0d7/scripts/extract-core-data.js","/_mintlify/custom/cubed3/476a9fa93e98d93b/consent.js"],"subdomain":"cubed3","siteName":"Cube Documentation","title":"Using `original_sql` and `rollup` pre-aggregations effectively - Cube Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-04-03T05:18:35.831Z","originalFileLocation":"recipes/pre-aggregations/using-originalsql-and-rollups-effectively.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Cube Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Using `original_sql` and `rollup` pre-aggregations effectively - Cube Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Cube Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://cubed3.mintlify.site/_mintlify/api/og/v2?division=Pre-aggregations\u0026amp;title=Using+%60original_sql%60+and+%60rollup%60+pre-aggregations+effectively\u0026amp;description=Recipe+for+materializing+expensive+cube+SQL+once+with+original_sql%2C+then+reusing+it+across+rollup+pre-aggregations+and+ad+hoc+queries.\u0026amp;theme=6d1e003873cec4de62649d7c\u0026amp;signature=fee60258acc768a0152d0d995f982527569ed43a2183649ca5a83fb212c3e2b1\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Using `original_sql` and `rollup` pre-aggregations effectively - Cube Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://cubed3.mintlify.site/_mintlify/api/og/v2?division=Pre-aggregations\u0026amp;title=Using+%60original_sql%60+and+%60rollup%60+pre-aggregations+effectively\u0026amp;description=Recipe+for+materializing+expensive+cube+SQL+once+with+original_sql%2C+then+reusing+it+across+rollup+pre-aggregations+and+ad+hoc+queries.\u0026amp;theme=6d1e003873cec4de62649d7c\u0026amp;signature=fee60258acc768a0152d0d995f982527569ed43a2183649ca5a83fb212c3e2b1\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/cubed3/JtLYPWhDFrYGSK8W/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Cube Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#5339CF\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/recipes/pre-aggregations/using-originalsql-and-rollups-effectively.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.cube.dev/#organization\",\"name\":\"Cube Documentation\",\"url\":\"https://docs.cube.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/cubed3/wCTntgEXVYYYnx4l/logo/light.svg?fit=max\u0026auto=format\u0026n=wCTntgEXVYYYnx4l\u0026q=85\u0026s=8bbf45ba64eac6116629064fac55aad7\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.cube.dev#website\",\"name\":\"Cube Documentation\",\"url\":\"https://docs.cube.dev\",\"publisher\":{\"@id\":\"https://docs.cube.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively#webpage\",\"url\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively\",\"name\":\"Using `original_sql` and `rollup` pre-aggregations effectively\",\"description\":\"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.\",\"dateModified\":\"2026-04-03T05:18:35.831Z\",\"isPartOf\":{\"@id\":\"https://docs.cube.dev#website\"},\"breadcrumb\":{\"@id\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Topics\",\"item\":\"https://docs.cube.dev/recipes\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pre-aggregations\",\"item\":\"https://docs.cube.dev/recipes/pre-aggregations/non-additivity\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using `original_sql` and `rollup` pre-aggregations effectively\",\"item\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively#article\",\"headline\":\"Using `original_sql` and `rollup` pre-aggregations effectively\",\"name\":\"Using `original_sql` and `rollup` pre-aggregations effectively\",\"description\":\"Recipe for materializing expensive cube SQL once with original_sql, then reusing it across rollup pre-aggregations and ad hoc queries.\",\"url\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively\",\"mainEntityOfPage\":{\"@id\":\"https://docs.cube.dev/recipes/pre-aggregations/using-originalsql-and-rollups-effectively#webpage\"},\"dateModified\":\"2026-04-03T05:18:35.831Z\",\"publisher\":{\"@id\":\"https://docs.cube.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.cube.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Cube Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Cube Documentation\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/recipes/pre-aggregations/using-originalsql-and-rollups-effectively.md","siteName":"Cube Documentation","nav":{"global":null,"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":"/docs/introduction"}]},{"tab":"Admin","pages":[{"title":"Admin","href":"/admin/connect-to-data"}]},{"tab":"Embedding","pages":[{"title":"Embedding","href":"/embedding"}]},{"tab":"Reference","pages":[{"title":"Reference","href":"/reference/data-modeling/cube"}]},{"tab":"Cube Core","pages":[{"title":"Cube Core","href":"/cube-core"}]},{"tab":"Recipes","groups":[{"group":"Topics","pages":[{"title":"Overview","mode":"wide","href":"/recipes"},{"group":"Data Modeling","pages":[{"group":"Calculations \u0026 Metrics","pages":[{"title":"Calculating averages and percentiles","href":"/recipes/data-modeling/percentiles"},{"title":"Calculating nested aggregates","href":"/recipes/data-modeling/nested-aggregates"},{"title":"Calculating filtered aggregates","href":"/recipes/data-modeling/filtered-aggregates"},{"title":"Calculating share of total","href":"/recipes/data-modeling/share-of-total"},{"title":"Calculating average order value","href":"/recipes/data-modeling/average-order-value"},{"title":"Calculating period-over-period changes","href":"/recipes/data-modeling/period-over-period"},{"title":"Reusing period-to-date logic across measures","href":"/recipes/data-modeling/reusable-period-to-date"}]},{"group":"Query-time parameters","pages":[{"title":"Configurable rolling windows and time shifts","href":"/recipes/data-modeling/dynamic-rolling-windows"},{"title":"Passing dynamic parameters in a query","href":"/recipes/data-modeling/passing-dynamic-parameters-in-a-query"}]},{"group":"Time Series \u0026 Calendars","pages":[{"title":"Working around string time dimensions","href":"/recipes/data-modeling/string-time-dimensions"},{"title":"Implementing custom time dimension granularities","href":"/recipes/data-modeling/custom-granularity"},{"title":"Implementing custom calendars","href":"/recipes/data-modeling/custom-calendar"},{"title":"Implementing data snapshots","href":"/recipes/data-modeling/snapshots"}]},{"group":"User \u0026 Event Analytics","pages":[{"title":"Daily, Weekly, Monthly Active Users (DAU, WAU, MAU)","href":"/recipes/data-modeling/active-users"},{"title":"Implementing event analytics","href":"/recipes/data-modeling/event-analytics"},{"title":"Implementing retention analysis \u0026 cohorts","href":"/recipes/data-modeling/cohort-retention"}]},{"title":"Cube style guide","href":"/recipes/data-modeling/style-guide"},{"title":"Designing metrics","hidden":true,"href":"/recipes/data-modeling/designing-metrics"},{"title":"Implementing Entity-Attribute-Value Model (EAV)","href":"/recipes/data-modeling/entity-attribute-value"},{"title":"Using Cube with dbt","href":"/recipes/data-modeling/dbt"},{"title":"dbt pull with the Cube CLI","href":"/recipes/data-modeling/dbt-cli"},{"title":"Generating the data model dynamically","href":"/recipes/data-modeling/using-dynamic-measures"},{"title":"Using dynamic union tables","href":"/recipes/data-modeling/dynamic-union-tables"},{"title":"Querying across data sources","href":"/recipes/data-modeling/cross-data-source-queries"},{"title":"Polymorphic cubes","href":"/recipes/data-modeling/polymorphic-cubes"},{"title":"Reusing a view measure across views","href":"/recipes/data-modeling/reusing-view-measures"},{"title":"Custom ordering for categorical values","href":"/recipes/data-modeling/custom-order"}]},{"group":"AI","pages":[{"title":"Agent-to-agent: using the Chat API as a tool","href":"/recipes/ai/agent-to-agent"}]},{"group":"Pre-aggregations","pages":[{"title":"Accelerating non-additive measures","href":"/recipes/pre-aggregations/non-additivity"},{"title":"Incrementally building pre-aggregations for a date range","href":"/recipes/pre-aggregations/incrementally-building-pre-aggregations-for-a-date-range"},{"title":"Disabling pre-aggregations","description":"We want to disable pre-aggregations unless some condition is fulfilled, e.g., unless the deployment is running in a production environment.","href":"/recipes/pre-aggregations/disabling-pre-aggregations"},{"title":"Using `original_sql` and `rollup` pre-aggregations effectively","href":"/recipes/pre-aggregations/using-originalsql-and-rollups-effectively"},{"title":"Refreshing select partitions","description":"Partition-level refresh patterns using refresh_key and FILTER_PARAMS when dimension values change long after the fact.","href":"/recipes/pre-aggregations/refreshing-select-partitions"},{"title":"Joining data from multiple data sources","href":"/recipes/pre-aggregations/joining-multiple-data-sources"},{"title":"Joining pre-aggregations with different refresh cadences","href":"/recipes/pre-aggregations/mixed-refresh-cadences-rollup-join"}]},{"group":"Configuration","pages":[{"title":"Referencing environment variables","href":"/recipes/configuration/environment-variables"},{"title":"Using SSL connections to a data source","href":"/recipes/configuration/using-ssl-connections-to-data-source"},{"title":"Optimizing data source usage","href":"/recipes/configuration/data-store-cost-saving-guide"},{"title":"Providing a custom data source for each tenant","href":"/recipes/configuration/multiple-sources-same-schema"},{"title":"Providing a custom data model for each tenant","href":"/recipes/configuration/custom-data-model-per-tenant"}]},{"group":"Core Data API","pages":[{"title":"Getting unique values for a field","href":"/recipes/core-data-api/getting-unique-values-for-a-field"},{"title":"Retrieving numeric values on the front-end","href":"/recipes/core-data-api/cast-numerics"},{"title":"Implementing custom sorting","href":"/recipes/core-data-api/sorting"},{"title":"Implementing pagination","href":"/recipes/core-data-api/pagination"},{"title":"Drilldowns","href":"/recipes/core-data-api/drilldowns"},{"title":"Real-Time data fetch in the REST (JSON) API","href":"/recipes/core-data-api/real-time-data-fetch"},{"title":"Using cloud groups and user attributes with Core Data APIs","href":"/recipes/core-data-api/cloud-groups-and-user-attributes"}]}]}]},{"tab":"API","pages":[{"title":"API","href":"/api-reference/introduction"}]}]},"basePath":"","title":"Using `original_sql` and `rollup` pre-aggregations effectively - Cube Documentation","deploymentId":"dpl_vSEmv961Ncyvz1psVwgUnTXQMSYk","buildId":"dpl_vSEmv961Ncyvz1psVwgUnTXQMSYk","dynamics":[],"chunks":[]}