Using originalSql and rollup Pre-aggregations Effectively

For cubes that are built from an expensive SQL query, we can optimize pre-aggregation builds so that they don't have to re-run the SQL query.

We can do this by creating a pre-aggregation of type originalSql on the source (also known as internal) database, and then configuring our existing rollup pre-aggregations to use the originalSql pre-aggregation with the useOriginalSqlPreAggregations property.

Storing pre-aggregations on an internal database requires write-access. Please ensure that your database driver is not configured with readOnly: true.

cube('Orders', {

  preAggregations: {
    base: {
      type: `originalSql`,
      external: false,

    main: {
      dimensions: [,],
      measures: [CUBE.count],
      timeDimension: CUBE.createdAt,
      granularity: `day`,
      useOriginalSqlPreAggregations: true,


With the above schema, the main pre-aggregation is built from the base pre-aggregation.

Did you find this page useful?