Skip to content

Serve the marts as views over the core

Context and Problem Statement

The names and the columns of the marts are the API of the product: Metabase binds its cards to a schema and a name, and an agent reads their descriptions. Today they are tables that dbt rebuilds, and they hold a reporting amount that was computed at the rate of the time of the build (ADR-0025). The core of ADR-0036 holds narrow facts in the currency of the account, so something has to give people and agents one wide row of one grain.

The maintainer set two requirements: Metabase reads views, and the reporting currency is computed in a view, by a join with the rates, beside the source amount. And a number has to mean one thing for each consumer, and match the account of the platform.

What does the layer of presentation look like, how does it stay fast on a view, and what does a column such as conversions mean?

Decision Drivers

  • A card or a question that works today works after the change, with no rebuild of the content of Metabase.
  • A filter of a dashboard reaches the index of a fact: PostgreSQL can flatten a view only when it is a plain join.
  • A number matches the platform, and a choice of the deployment is named as one.
  • The cost of a query follows the grain that it needs, and a table is added only when a measurement asks for one.
  • The settings that protect a view from a full scan apply to every deployment, as code (ADR-0016).

Considered Options

For the marts:

  • Views of one grain, under today's names
  • Tables, as today
  • Materialized views

For money:

  • Three columns for an amount: the number in the currency of the account, the code of the currency, and the amount in the reporting currency
  • The reporting amount only
  • A column for each currency

For conversions:

  • The metric of the platform, with the choice of the deployment in conversions_primary
  • As today: the sum of the primary actions of the deployment

For an aggregate of an account and a day:

  • None, until a card exceeds 2 seconds at the target scale
  • In the basic set from the start

Decision Outcome

Chosen options: "Views of one grain, under today's names", "Three columns for an amount", "The metric of the platform, with the choice of the deployment in conversions_primary" and "None, until a card exceeds 2 seconds at the target scale", because a view of a plain join costs no storage and goes no stale, a change of a rate needs no rebuild, the first requirement of a number is that it matches the platform, and the grain answers a heavy query better than a new table does.

In practice this means:

  • Names. All 13 marts stay under their names, as views over the core. conversion_actions and metric_definitions join them (ADR-0043). Columns are only added, at the end. A rename is a new version of the dbt model (versions:), and the old one lives for at least one release (ADR-0044).
  • The form of a view. A row of the view is a row of the fact.

    Columns Example From
    Keys and references platform, platform_name, client_id, client_name, account_id, account_name, campaign_id, ad_group_id, ad_id The fact and the dimensions; identifiers as text, from the dimension
    Current names and statuses campaign_name, campaign_status, campaign_state, campaign_type, is_listed The dimensions
    Time report_date, time_zone The fact, dim_account
    Money of the account spend, conversion_value, currency The fact
    Money for reporting spend_reporting, conversion_value_reporting, reporting_currency, fx_rate, fx_rate_date, is_fx_rate_carried_forward The fact and core.fx_rates_daily, one join, rounded only for display
    Counters impressions, clicks, conversions, all_conversions, conversions_primary The fact
    Service loaded_at, is_partial_day, is_final, is_account_active The fact, core.loads, dim_account
  • No ratios in a row. CTR, CPC, CPA and ROAS are aggregations in Metabase and in SQL from metric_definitions, over sums that were never rounded. A sum by days then equals the total, and the total equals the account.

  • A plain join. A view has no GROUP BY, DISTINCT, LIMIT or window function, so PostgreSQL flattens it and carries a filter down to the index of a fact. The dimensions join by LEFT JOIN on a unique key, so the planner drops those that a query does not use. A view of ads has seven tables, and a query with two views does not fit the default of 8, so the roles that read get from_collapse_limit and join_collapse_limit of 12.
  • Identifiers as text. They come from the dimension, which holds both forms: the values of Meta exceed 2^53, the browser of Metabase rounds such numbers, and f.id::text in the view would stop the use of the index.
  • Dates of dimensions. The marts of dimensions no longer group the facts for their first and last days and for name_count: those are stored in dim_*, so a view stays a join.
  • Contracts. A contract of dbt on a view keeps names and types. The primary_key constraints of today's contracts move to the tables of the core, and type/PK for Metabase stays in meta.
  • Money. Metabase formats a currency by column and not by row, so each amount has three columns: the number in the currency of the account (format Normal), the code (text, a filter) and the reporting amount (type/Currency, in the unit from .env). Only *_reporting adds up across accounts, and the description of a column says so to a person and to an agent. The conversion goes by row, at the rate of the day of the row. The reporting currency is one for a deployment; one for each client, a second pair of columns *_client from dim_client.reporting_currency, is planned for v0.9.
  • conversions. It is the metric of the platform, such as metrics.conversions of Google, and matches the account. conversions_primary is the choice of the deployment from conversion_actions.toml, available at the levels of ad groups and ads only with the module of ADR-0036.
  • The rule of the grain. A dashboard reads the coarsest grain that answers its question.
  • The threshold. A card moves to an aggregate after 2 seconds at the target scale. The aggregate table lies in a schema closed to readers and holds only counters and sums in the currency of the account, and a view in marts adds names and the rate, so a card moves with no new column, and no converted amount is stored. dbt updates it incrementally, and G3 compares it with the view for the last 90 days. A snapshot under the name of a view is not allowed: the name of a mart does not change its nature silently.
  • Metabase, in every deployment, set by metabase-init on every up:
    • has_field_values from the code for each column: list for the platform, status, state, currency and the type of a campaign, search for names, and none for identifiers, dates and measures.
    • The sync stays hourly, and refingerprinting stays off, as by default.
    • The scan of values stays daily, placed after the nightly load, with no scan on demand.
    • The semantic types through the API, as today, with type/FK and fk_target_field_id on a view, where PostgreSQL gives no foreign key.
    • The policy of cache Adaptive for the whole instance, the only level in OSS: a minimum of 1 second and a multiplier of 10.
    • MB_DB_QUERY_TIMEOUT_MINUTES of 5, as the statement_timeout of metabase_reader, and a wait of 30 seconds for a connection from the pool. The pool stays at 15.
    • The linked filters of a dashboard take their values from ad_stats_campaign_daily, as today, and the filter of the state of a campaign joins them.
    • Transforms and the persistence of models stay off: both write to the warehouse.

The other options were not chosen for these reasons:

  • Tables repeat the names and the amounts of the core, at 2.3 times the size, and they go stale until the next build (ADR-0036).
  • Materialized views need a full refresh, as PostgreSQL has no incremental one and pg_ivm is not in the official image, and each refresh writes all of it again.
  • The reporting amount only hides the source amount, and a reader could not check a row against the account.
  • A column for each currency multiplies columns for what a filter does.
  • The sum of the primary actions as conversions can be explained only to those who read conversion_actions.toml, and it does not match the account.
  • An aggregate from the start is one more table, one more check and more work in the short cycle, for queries that the view of campaigns answers in 0.4 s at the density of the limit. It also cannot apply the filter of a campaign that these cards have.

Consequences

  • Good, because an existing card goes on working: its table is now a view of the same name.
  • Good, because a rate or a reporting currency changes with no rebuild of the marts.
  • Good, because a filtered query stays in tens of milliseconds at 48.8 million rows, as measured.
  • Good, because conversions is the metric that the account shows, on every platform.
  • Bad, because a view without a filter still reads the whole fact: month and platform over 12 months takes 6.7 s on the view of ads at the density of the limit.
  • Bad, because the first load of the values of a linked filter goes through the fact of campaigns.
  • Bad, because the meaning of conversions changes for a deployment that set conversion_actions.toml, and it has to read conversions_primary instead.
  • Bad, because sync and scan keep costing, and the settings have to be kept by code on every up.

More Information

  • Implementation status, as of November 2026: the 13 marts are views over the core under their names, with the columns of v0.4 first and the new ones after them, and conversion_actions joins them (dbt/models/marts/): a plain join of a fact with its dimensions on their unique keys by LEFT JOIN, the IDs as text from the dimensions, three columns for each amount with the rate of the day, its date and its flag, conversions as the metric of the platform and conversions_primary as the sum of the primary actions of a campaign, a LEFT JOIN LATERAL that looks the row up once in the key of the conversions by action and that the planner leaves out of a question that does not read it, none at the levels of ad groups and ads, the states and is_listed, loaded_at from core.loads and is_account_active; ad_campaign_names over core.dim_campaign_versions; an enforced contract on each view and no constraint; and a from_collapse_limit and a join_collapse_limit of 12 for metabase_reader and ai_reader (postgres/warehouse.sql). The rate of a row is fx_rate_into_reporting_currency, as Metabase 0.64.1 gives a decimal column whose name ends in rate the type of a share, a percentage, each time that it analyzes it; the date and the flag are fx_rate_date and is_fx_rate_carried_forward. A view reads the core alone, and the platforms, a seed, are rows written into its text when it is built (dbt/macros/platforms.sql), as a run loads every seed again with a TRUNCATE. "Metabase, in every deployment" is in place: since v0.4.x has_field_values in the meta of dbt, the scan at METABASE_SCAN_TIME, the hourly sync, the policy of cache, MB_DB_QUERY_TIMEOUT_MINUTES of 5, and the wait of 30 seconds as MB_JDBC_DATA_WAREHOUSE_CONNECTION_POOL_CHECKOUT_TIMEOUT_MS, and for v0.5 type/PK, type/FK and fk_target_field_id on the views from the meta of dbt, with the semantic type of every other column, which puts right a type/PK that a sync gave the columns of the keys of the tables of v0.4 (metabase/metadata.py), and the filter of the state of a campaign among the linked filters of the dashboard Advertising, on ad_stats_campaign_daily, for its cards of the campaigns, which read conversions_primary, with the KPIs Cost per Primary Conversion and Primary Conversion Rate of the campaigns (metabase/advertising.py). The one-shot job marts-init builds the views again on every ./agoranomos up, before metabase-init (ADR-0039). is_partial_day ends ad_stats_campaign_daily since v0.6, true on a row of a day that only a load of the kind intraday took, and the card Today, as of the load, of the dashboard Advertising reads those rows, while its other cards and the metrics of Metabase leave them out (ADR-0051); is_final comes with v0.7, metric_definitions with v0.8, and the columns *_client with v0.9. metabase-init already keeps the metadata of the marts (ADR-0016).
  • The facts behind this record, measured in October 2026 on the stand of ADR-0036, in milliseconds, the best of three, with a limit of 2 GiB, shared_buffers of 512 MB and JIT on, which the stack has off. With jit=off, the view of ads took 1,393 ms and 357 ms on the two heaviest queries:

    Query Wide table View of ads View of campaigns
    One account, 30 days by day 1.7 3.9 1.9
    A client, top 20 campaigns over 7 days 61 13 3
    Filter on the name of an account, 90 days 1,623 8 3
    7 days, all accounts, by platform 76 51 18
    Month and platform over 12 months 2,064 1,623 312
    Sum of the whole table 959 546 204
    • At the density of the limit, 48.8 million rows and a limit of 4 GiB, month and platform over 12 months took 6,728 ms on the view of ads, 417 ms on the view of campaigns and 44 ms on an aggregate of an account and a day.
    • A view with LEFT JOIN on unique keys was 3.4 times faster than one with INNER JOIN on the full sum, as the planner dropped the dimensions and the rates.
    • Metabase marked 17 of 23 fields of a view as list, and the scan took 3.2 to 3.9 s for each, 57 s for one view of 7 million rows. Its sync of the whole schema took 5 to 7 seconds.
    • A view is planned "just as if we'd written them out manually", which GROUP BY, DISTINCT, LIMIT and window functions prevent (The Rule System). Metabase formats a currency by column (#9879, open since 2019), and its docs advise summary tables for slow cards (Making dashboards faster).
    • Supermetrics and Adverity convert each row at the rate of its date (Supermetrics, Adverity). Kimball stores a second, standard currency column built by ETL (Multiple currencies); computing it on read departs from him, as the maintainer requires.
    • Checked on Metabase 0.64.1 on 1 November 2026, by calls to a running instance:
    • PUT /api/cache takes {"model": "root", "model_id": 0, "strategy": {"type": "ttl", "multiplier": 10, "min_duration_ms": 1000}}, in whole numbers, and GET /api/cache gives the same back, or an empty list before the first policy. A policy for one database answers 402 in OSS. A saved question of 1.3 s came from the cache in 0.04 s, once Metabase had recorded its average, some seconds after its first runs.
    • PUT /api/database/:id keeps a schedule only with let-user-control-scheduling in the details of the connection, and otherwise draws both schedules again. It makes a daily schedule from an hour alone and drops a minute, so the scan starts at the start of an hour, the first whole hour after the nightly load, and not one hour after it to the minute.
    • Measured on 11 and 12 November 2026 on synthetic data, through the API of Metabase, on a stack without the demo with warehouse-db at 3 GiB, on a server with 2 cores and 4 threads of 2012 (System requirements):
    • Each card of the dashboard Advertising with its default filters, against the threshold of 2 seconds: at the density of the agency, 15,000 rows of ads a day over 400 days, five of the 22 cards are above it, at 3.2 to 5.1 s, and at the density of the limit, 80,000 a day over 100 days, eleven, up to 29.5 s for the card Ads. Most of the time goes to conversions_primary, the subquery of the view of campaigns, which runs for each row that a question reads and for each mention of the column; the card Ads groups the 12 weeks of ads with no required filter. On 12 November 2026, with conversions_primary looked up by a LEFT JOIN LATERAL once for each row that a question reads, three cards are above it at the density of the agency, Top campaigns by spend and Campaigns at 2.2 to 2.3 s and Ads at 4.0 s, and eleven at the density of the limit, where the lookups of the 504,000 rows of campaigns of the 12 weeks take about 8 s.
    • The values of the linked filters on the view of campaigns, on first use: 0.2 to 0.8 s at both densities.
    • Metabase with 20 clients at once at the density of the agency: no failure, and a peak of 1,531 MiB of its 2,176 MiB.
    • The nightly scan: Metabase 0.64.1 scans only the fields whose values a filter has asked for once. After the first use of the 96 fields that are a list, the scan took 68 s at the density of the agency over 400 days and 78 s at the density of the limit over 100 days, as it reads every row of each view.
    • Not checked yet, and to be checked with the code:
    • The match with the account on real data, the main requirement of the product, for a long-running deployment to show against an independent warehouse.
    • The cards on a server of 8 vCPUs, and at the limit with its 16 GiB and its 36 months.
    • Open at review: the wording of "matches the account" as the acceptance of each connector. The proposal: the source amounts and counters, in the currency and the time zone of the account, for days older than the window of restatements, equal the report of the platform under the same filters of status and attribution; converted amounts and ratios match up to the rounding of the display; the total of an account compares with all entities, the removed too; and a page "Why the numbers differ" lists the rest.
    • Related decisions: with ADR-0036, this record supersedes ADR-0025 at acceptance. The view rebuild is in ADR-0039, and the rates in ADR-0042. With ADR-0036 it replaces the conversions of primary actions in the facts of ad groups and ads of ADR-0034. has_field_values is one more field of the scheme of ADR-0016, which does not change.
    • Revisit this record when a card exceeds the threshold, when Metabase formats a currency by row, or when PostgreSQL gains an incremental refresh of a materialized view.