|
|
|
|
|
- Overview
- Definition
- When to use a materialized view?
- Creating a materialized view
- Overview
- Creation from the data model editor
- Creation by using the SQL code
- Using a materialized view
- Overview
- Rights on a materialized view
- Modifying the content of a materialized view
- WLanguage functions used to handle a materialized view
- Scheduled refresh task for a materialized view
- Overview
- Scheduled refresh of a materialized view in the HFSQL Control Center
- Create a refresh task for a view materialized by programming
- Index on a materialized view
Materialized view
Available only with this kind of connection
Definition A materialized view is a physical data source defined by an SQL query. This materialized view is physically created on the HFSQL server. It can be used like an HFSQL data file by applications that access the database. The application can use or handle a materialized view by using the regular file functions. Manipulated data are not updated automatically: it is necessary to request data updates. When to use a materialized view? Using a materialized view proposes several benefits: - Independence with respect to the physical structure of the data:
The materialized view corresponds to an abstraction layer between the data structure and the data use. If the physical structure of data evolves, the application code does not change. Only the base query of view must be adapted to the new structure. - Process acceleration
Using a materialized view is interesting if extracting data from the view is a long process and if the data does not have to be real time. For example:- statistics,
- reporting,
- data binding,
- selections for mailshots,
- targeting,
- creating "flat" data files,
- ...
Creating a materialized view Overview Several methods can be used to create a materialized view: - Create the materialized view from the data model editor. In this case, to use the materialized view, the data must be updated on the server. This update can be performed:
- via the automatic data modification (performed when installing the application for example).
- via HUpdateView.
- Creating the materialized view by using the SQL "CREATE MATERIALIZED VIEW" code in the application.
Creation from the data model editor To create a materialized view from the data model editor: - Start the view creation wizard:
- In the ribbon, on the "Analysis" tab, in the "Creation" group, expand "New" and select "View".
- On the "Analysis" pane, select the "Views" folder then select the "New view" option of context menu.
- In the wizard, select "Create a materialized view" then go to the next screen (arrow at the bottom of wizard).
- Specify the name of the view to create then select the edit mode of base query for the view:
- Wizard. In this case, the query of the view is created via the wizard for query creation. The query is displayed graphically. The query can be modified at any time via the wizard.
- SQL code. In this case, you directly enter the SQL code for selecting the elements selected by the view.
- The materialized view is created. By default, it is not associated with a connection. To associate the view with a connection defined in the data model editor:
- On the "Analysis" pane, select the materialized view that was just created.
- In the context menu (right mouse click), select "Description of the view".
- In the window that is displayed, you can modify the name of the materialized view and specify the connection associated with the materialized view.
- Validate.
- Generate the analysis to use the view materialized in the application code: under the "Analysis" pane, in the "Analysis" group, pull down "Generation" and select "Generation".
Remarks: - A key or a composite key will be created based on the "ORDER BY" statement.
- The materialized views cannot contain parameters.
Creation by using the SQL code To create a materialized view using SQL code, all you have to do is use the CREATE MATERIALIZED VIEW command in the SQL code of the query. For example: Req_Vue is Data Source
MonCodeVueMatérialisée is string
MonCodeVueMatérialisée = [
Create materialized view Vue_Client
AS SELECT * FROM Client
]
HExecuteSQLQuery(Req_Vue, ConnexionHFSQL, MonCodeVueMatérialisée)
Warning The SQL code used to create the materialized view must refer only to the fields and data files defined in the analysis. For example, references to stored queries cannot be used in this code. Using a materialized view Overview To use a materialized view, simply use the HFSQL functions for accessing data files. The <File Name> parameter will correspond to the name of the materialized view. Like a standard data file, a materialized view can be: - browsed using the HFSQL functions (FOR EACH, HRead*, ...),
- associated with a control (Table control, List Box control, ...).
Note: If the materialized view has not been created in the data model editor, it is necessary to use the HDeclareExternal function before manipulating it. Rights on a materialized view A materialized view corresponds to a data file. Right management is handle the same way as for data files. These rights can be configured: Note: The HInfoViewRights function is used to find out the current rights on the materialized view. Modifying the content of a materialized view The content of a materialized view is updated: WLanguage functions used to handle a materialized view The following WLanguage functions are used to handle the materialized views:
| | HInfoView | Returns information about a materialized view. | HRefreshView | Asks to recalculate the content of a materialized view. | HUpdateView | Creates or updates the description of an SQL view or materialized view from the analysis to an HFSQL server. |
Scheduled refresh task for a materialized view Overview To refresh the content of a materialized view, you can create a scheduled materialized view refresh task. This scheduled task for refreshing a materialized view can be created and manipulated: - via the HFSQL Control Center.
- programmatically.
Scheduled refresh of a materialized view in the HFSQL Control Center In the HFSQL Control Center, refresh tasks for a materialized view can be defined at server or database level. To create a refresh task: - If necessary, connect to an HFSQL server and display the description of the server or one of its databases (double-click on the server or database name in the tree structure).
- Click the "Scheduled elements" tab.
- In the Ribbon, in the "Scheduled items" group, pull down "New schedule" and select "Schedule a materialized view refresh". The wizard for creating a scheduled materialized view refresh task is launched.
- Select the materialized views to be optimized:
- All database views,
- A selection of database views.
- Define task frequency: month, day, hour.
- Give your scheduled task a description and confirm the wizard.
- The scheduled refresh task appears in the "Scheduled items" tab of the HFSQL Control Center.
It is possible to delete, execute or modify the scheduled refresh task. To modify a scheduled refresh task: - If necessary, connect to an HFSQL server and display the appropriate server or database tab.
- Click the "Scheduled elements" tab.
- Select the materialized view refresh job to be modified.
- In the ribbon, in the "Scheduled elements" group, click "Edit".
You also have the ability to use the context menu of the scheduled element ("Edit" option). - A description window of the scheduled element is displayed. All features are grouped together on several tabs:
- Tab "General": Defines whether the view refresh task is active.
- Tab "Scheduling": Defines the scheduled optimization execution options (month, day, time).
New in version 2025Tab "Execution History": This tab appears when the scheduled optimization has been executed automatically. This tab lists the different automation executions of the scheduled task, indicating: - the optimization start date,
- optimization status: completed, in progress, error,
- running time,
- the user who launched the optimization,
- if launched manually (via HExecuteScheduling).
- Validate.
Create a refresh task for a view materialized by programming The creation of a refresh task for a view materialized by programming is carried out using a variable of type hScheduleMaterializedView. To create a refresh task for a materialized view: - Create a variable of type hScheduleMaterializedView and describe its various characteristics.
- Add planned optimization using HAddScheduling.
Then, this task can be handled via the following functions: | | HAddScheduling | Adds a new scheduled item to an HFSQL server: scheduled task (stored procedure), backup, optimization or refresh of a materialized view. | HDeleteScheduling | Delete a scheduled item on an HFSQL server: scheduled task (stored procedure), backup, optimization, refresh of a materialized view. | HExecuteScheduling | Immediately executes a scheduled item regardless of its scheduling: scheduled task (stored procedure), backup, optimization, refresh of a materialized view. | HModifyScheduling | Modify a scheduled item on an HFSQL server: scheduled task (stored procedure), backup, optimization, refresh of a materialized view. |
New in version 2025An execution history is automatically recorded when the refresh task is automatically executed (or when it is executed using the HExecuteScheduling function). This history can be manipulated: - via the HFSQL Control Center. When the scheduled task has been executed, the "Execution history" tab is available in the scheduled item description window. This tab allows you to view all the characteristics of the planned element's executions.
- by programming, using the following functions:
| | | Clears the execution history of scheduled jobs on an HFSQL server. | | Deletes the executions of a scheduled job on an HFSQL server. This job can be a scheduled task (stored procedure), backup, optimization or a materialized view refresh. | | Lists the executions of a scheduled job on an HFSQL server. This job can be a scheduled task (stored procedure), backup, optimization or a materialized view refresh. |
Index on a materialized view To create an index on a materialized view, use CREATE INDEX. If the materialized view is refreshed, the indexes are updated automatically: there's no need to recreate the indexes.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|