Profile Ontology (ANALYZE ONTOLOGY)
Profiling collects statistics about the data behind your ontology: how many values each property has, how many are distinct, the most common values, and value ranges. Data agents use these statistics to understand what is really in the data. They can then pick the right concept, match a user's words to values that actually exist (for example AMERICAN EXPRESS COMPANY for "AmEx"), and resolve date and numeric filters against real ranges.
In SQL, profiling is run with the ANALYZE ONTOLOGY statement. To profile from the UI, see Profile Ontology in the Timbr Platform.
An ontology tells the agent what the data means. Profiling tells it what the data contains. Without statistics, the agent has to guess filter values; with them, it matches real ones. See AI Best Practices.
What is collected
For each property of the analyzed mappings, views and cubes:
| Statistic | Description |
|---|---|
| Non-null count | Number of values that are not null |
| Distinct count | Number of distinct values |
| Top-k values | The most frequent values and how often each occurs (up to topk values per property) |
| Value range | Minimum and maximum values for numeric and date properties |
Non-null and distinct counts can be reviewed per property in Profile Ontology in the Timbr Platform. Top-k values and value ranges are not shown in the UI; they are used by data agents.
How it runs
ANALYZE ONTOLOGYruns asynchronously as a background job on the Timbr server. The statement submits the analysis and returns; it does not wait for statistics to be collected.- The run applies to the ontology you are connected to.
- Statistics are collected for every property of each mapping, view and cube in scope. Analyzing a concept analyzes all of its mappings.
- The SQL statement and the Profile Ontology page in the Timbr Platform offer the same scopes and options. Use SQL to script profiling, run it from external tools, schedule it with cron expressions, or chain it after cache refresh jobs.
- Statistics are collected per property and kept for a period set by
ttl. Within that period, existing statistics are reused rather than recalculated. See What gets re-analyzed. - Runs can be scheduled with
CREATE JOBto keep statistics current.
Syntax
ANALYZE ONTOLOGY
[ { CONCEPT | VIEW | CUBE } [ ( target_name [, target_name, ...] ) ] ]
[ OPTIONS ( option_name = value [, ...] ) ];
Scope
| Scope | What is analyzed |
|---|---|
| (none) | All mappings, views and cubes in the ontology |
CONCEPT | Concepts and their mappings |
VIEW | Ontology views (not cubes) |
CUBE | Ontology cubes only |
With a scope, you can list the specific targets to analyze. Without a list, every object of that type is analyzed.
ANALYZE ONTOLOGY CONCEPT (customer, `order`);
ANALYZE ONTOLOGY VIEW (sales_summary, customer_details);
ANALYZE ONTOLOGY CUBE (sales_cube);
Options
| Option | Type | Default | Description |
|---|---|---|---|
parallel | Integer | 1 | Number of parallel threads used to collect statistics. Higher values finish faster on large ontologies but use more resources on the server and the source database. |
topk | Integer | 200 (or the system default) | Maximum number of most-frequent values collected per property. |
ttl | Integer (minutes) | 10080 (7 days) | How long statistics stay valid. Statistics older than this are recalculated on the next run; newer ones are kept. |
force | Boolean | false | Recalculate statistics for every property in scope, even if its statistics are still within ttl. |
refresh_on_update | Boolean | false | Also recalculate statistics for mappings, views and cubes whose definition changed since they were last analyzed, even if still within ttl. |
only_new | Boolean | false | Only analyze properties that have no statistics yet, such as properties added since the last run. Properties that already have statistics are skipped, even if their statistics are older than ttl. |
sample | Boolean | false | Analyze a sample instead of the full data. Much faster on very large tables, at the cost of precision. |
timeout | Long (seconds) | 432000 (5 days) | Maximum time to wait for the analysis to complete before it times out. |
What gets re-analyzed
For each property in scope, a run decides whether to collect statistics:
| Run | Property with no statistics | Statistics within ttl | Statistics older than ttl |
|---|---|---|---|
| Default | Analyzed | Skipped | Re-analyzed |
refresh_on_update = true | Analyzed | Re-analyzed if its mapping, view or cube changed; otherwise skipped | Re-analyzed |
force = true | Analyzed | Re-analyzed | Re-analyzed |
only_new = true | Analyzed | Skipped | Skipped |
In other words, a normal run already skips statistics that are still within ttl. only_new is stricter: it skips any property that already has statistics, however old.
force and only_new are separate optionsThey have opposite purposes: force re-analyzes properties that already have statistics, while only_new analyzes only properties that have none. Set at most one of them in a run.
Choosing options
| Goal | Options |
|---|---|
| First profile of a new ontology | force = true, a higher parallel |
| Routine refresh | Defaults, or a ttl that matches your data load cycle |
| Pick up model changes without a full rerun | refresh_on_update = true |
| Cover only newly added objects | only_new = true |
| Very large tables | sample = true |
| Deeper value coverage for high-cardinality columns | A higher topk |
Examples
Analyze the entire ontology with default options:
ANALYZE ONTOLOGY;
Analyze specific concepts:
ANALYZE ONTOLOGY CONCEPT (customer, `order`, product);
Analyze all views with 4 threads and statistics valid for one day:
ANALYZE ONTOLOGY VIEW
OPTIONS (
parallel = 4,
ttl = 1440
);
Analyze specific cubes using sampling:
ANALYZE ONTOLOGY CUBE (sales_cube, inventory_cube)
OPTIONS (
sample = true,
parallel = 2
);
Force a full re-analysis with deeper top-k coverage:
ANALYZE ONTOLOGY
OPTIONS (
force = true,
parallel = 8,
topk = 1000
);
Refresh statistics for objects that changed since the last run:
ANALYZE ONTOLOGY
OPTIONS (
refresh_on_update = true,
parallel = 4
);
Analyze only objects that have never been analyzed:
ANALYZE ONTOLOGY
OPTIONS (only_new = true);
Schedule profiling with a job
To keep statistics current, wrap ANALYZE ONTOLOGY in a job. The job runs the statement on its schedule, or whenever you call RUN JOB.
CREATE OR REPLACE JOB {job_name}
REFRESH '{refresh_value}'
AS ANALYZE ONTOLOGY [ { CONCEPT | VIEW | CUBE } [ ( targets ) ] ] [ OPTIONS ( ... ) ]
{refresh_value} is one of none, daily, weekly, monthly, yearly, or a cron expression. Cron schedules are in UTC. See Intervals for refresh_value.
Daily profile of the whole ontology at 02:00 UTC, refreshing anything older than a day or changed since the last run:
CREATE OR REPLACE JOB profile_sales_ontology_daily
REFRESH '0 2 * * *'
AS ANALYZE ONTOLOGY
OPTIONS (
parallel = 4,
ttl = 1440,
refresh_on_update = true
)
Weekly deep profile of key concepts:
CREATE OR REPLACE JOB profile_core_concepts_weekly
REFRESH 'weekly'
AS ANALYZE ONTOLOGY CONCEPT (customer, `order`, product)
OPTIONS (
force = true,
parallel = 4,
topk = 500
)
An on-demand job (REFRESH 'none') that only runs when called:
CREATE OR REPLACE JOB profile_cubes
REFRESH 'none'
AS ANALYZE ONTOLOGY CUBE
OPTIONS (force = true)
RUN JOB profile_cubes
Re-profile after a cache refresh
When the data behind a view or cube is refreshed by a cache job, its statistics should follow. ANALYZE ONTOLOGY cannot be placed inside a bulk job's BEGIN … END body, but a bulk job can call a profiling job with RUN JOB. The profiling job starts only after all the cache refreshes in the bulk job have finished.
-- Profiling job, triggered by the pipeline below
CREATE OR REPLACE JOB profile_sales_cube
REFRESH 'none'
AS ANALYZE ONTOLOGY CUBE (sales_cube)
OPTIONS (force = true, parallel = 4)
-- Daily pipeline: refresh the caches, then re-profile
CREATE OR REPLACE JOB refresh_sales_pipeline
REFRESH 'daily'
PARALLEL '2'
AS BEGIN
REFRESH CACHE MAPPING map_orders
WHERE order_date > CURRENT_DATE - 2;
REFRESH CACHE VIEW sales_cube;
RUN JOB profile_sales_cube;
END
Manage profiling jobs
Profiling jobs are managed like any other job:
SHOW CREATE JOB `profile_sales_ontology_daily` -- show the job definition
RUN JOB profile_sales_ontology_daily -- run now
DROP JOB profile_sales_ontology_daily -- remove the job
The Automation section of the Analysis Options dialog in Profile Ontology creates the same kind of job, and it then appears in Scheduled Jobs.
Monitor runs
Analysis runs are recorded in the job system tables. Direct ANALYZE ONTOLOGY statements are recorded with job_type = 'analyze'; scheduled runs are recorded under the job's own name.
-- Recent profiling runs in this ontology
SELECT job_name, job_type, status, status_log, start_time, end_time, duration, job_sql
FROM timbr.sys_jobs_history
WHERE job_type = 'analyze' OR lower(job_sql) LIKE 'analyze ontology%'
ORDER BY start_time DESC;
-- Currently running jobs
SELECT * FROM timbr.sys_jobs_running;
If a run fails, status_log contains the error. See Cache/Jobs tables.
Permissions
ANALYZE ONTOLOGY requires EDIT permission on the target ontology. See Permissions required by feature.
Best practices
- Profile at setup. Run a full, forced analysis when a new ontology or use case goes live.
- Match frequency to data loads. Schedule profiling to follow your data refresh cycle. A daily load deserves a daily profile, and a
ttlof about one cycle. - Re-profile after changes. Use
refresh_on_update = trueso changed mappings, views and cubes are picked up without re-analyzing everything. - Follow cache refreshes. Chain a profiling job after cache refresh jobs with
RUN JOB. - Target what matters. Profile frequently changing or business-critical concepts more often than the rest of the ontology.
- Tune resources. Increase
parallelfor large ontologies, usesamplefor very large tables, and schedule heavy runs outside peak hours. - Watch duration. Track run times in
timbr.sys_jobs_historyand adjustparallel, scope or schedule as the ontology grows.