Teiid provides a short cut to creating an internal materialized view table via the _lookup_ function. |
The _lookup_ function provides a way to get a value out of a table when a key value is provided. The function automatically caches all the values in the referenced table for the specified key/value pairs. The cache is created the first time it is used in a particular Teiid process. Subsequent lookups against the same table using the same key and value columns will use the cached information. |
The _lookup_ function provides a way to accelerate getting a value out of a table when a key value is provided. The function automatically caches all of the key/return pairs for the referenced table. This caching is performed on demand, but will proactively load the results to other members in a cluster. Subsequent lookups against the same table using the same key and return columns will use the cached information. |
|
This caching solution is appropriate for integration of "reference data" with transactional or operational data. Reference data are static data sets – typically small – which are used very frequently in most enterprise applications. Examples are ISO country codes, state codes, and different types of financial instrument identifiers. |
This caching solution is appropriate for integration of "reference data" with transactional or operational data. Reference data is usually static and small data sets that are used frequently. Examples are ISO country codes, state codes, and different types of financial instrument identifiers. |
h2. Usage |
This caching mechanism is automatically invoked when the lookup scalar function is used. The lookup function returns a scalar value, so it may be used anywhere an expression is expected. Each time this function is called with a unique combination of referenced table, return column, and key column \(the first 3 arguments to the function), the Teiid System caches the entire contents of the table being accessed. Subsequent lookup function calls with the same combination of parameters will use the cached table data. function). |
See the [Lookup Function] in the Reference Guide for more information on use of the _lookup_ function. |
... |
* No mechanism is provided to refresh code tables |
* Only a single key/return column is cached - values will not be session/user specific. |
h2. Materialized View Alternative |
... |
{code} |
Here MatISOCountryCodes is a view selecting from ISOCountryCodes that has been marked as materialized and has a primary key or and index on CountryName. The scalar subquery will use the index to lookup the country code for each country name in tbl. |
Reasons to use a materialized view: |
... |
* Proper materialized views have built\-in system procedure/table support. |
* More control of via the cache hint. |
* The ability to use OPTION NOCACHE. |
... |
Teiid provides a short cut to creating an internal materialized view table via the lookup function.
The lookup function provides a way to accelerate getting a value out of a table when a key value is provided. The function automatically caches all of the key/return pairs for the referenced table. This caching is performed on demand, but will proactively load the results to other members in a cluster. Subsequent lookups against the same table using the same key and return columns will use the cached information.
This caching solution is appropriate for integration of "reference data" with transactional or operational data. Reference data is usually static and small data sets that are used frequently. Examples are ISO country codes, state codes, and different types of financial instrument identifiers.
This caching mechanism is automatically invoked when the lookup scalar function is used. The lookup function returns a scalar value, so it may be used anywhere an expression is expected. Each time this function is called with a unique combination of referenced table, return column, and key column (the first 3 arguments to the function).
See the Lookup Function in the Reference Guide for more information on use of the lookup function.
lookup('ISOCountryCodes', 'CountryCode', 'CountryName', 'United States')
The lookup function is a shortcut to create an internal materialized view with an appropriate primary key. In many situations, it may be better to directly create the analogous materialized view rather than to use a code table.
SELECT (SELECT CountryCode From MatISOCountryCodes WHERE CountryName = tbl.CountryName) as cc FROM tbl
Here MatISOCountryCodes is a view selecting from ISOCountryCodes that has been marked as materialized and has a primary key and index on CountryName. The scalar subquery will use the index to lookup the country code for each country name in tbl.
Reasons to use a materialized view:
Steps to create a materialized view:
Just as with the lookup function, the materialized view table will be created on first use and reused subsequently. See the Materialized Views for more.