Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions presto-docs/src/main/sphinx/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Administration
admin/spill
admin/exchange-materialization
admin/cte-materialization
admin/materialized-views
admin/resource-groups
admin/session-property-managers
admin/function-namespace-managers
Expand Down
27 changes: 27 additions & 0 deletions presto-docs/src/main/sphinx/admin/materialized-views.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
==================
Materialized Views
==================

Introduction
------------

A materialized view stores the results of a query physically, unlike regular views which are virtual.
Queries can read pre-computed results instead of re-executing the underlying query against base tables.

Materialized views improve performance for expensive queries by calculating results once during
refresh rather than on every query. Common use cases include aggregations, joins, and filtered
subsets of large tables.

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.
Use at your own risk in production environments.

To enable materialized views, set :ref:`admin/properties:\`\`experimental.legacy-materialized-views\`\`` = ``false``
in your configuration properties, or use ``SET SESSION legacy_materialized_views = false``.

See Also
--------

:doc:`/sql/create-materialized-view`, :doc:`/sql/drop-materialized-view`,
:doc:`/sql/refresh-materialized-view`, :doc:`/sql/show-create-materialized-view`
20 changes: 19 additions & 1 deletion presto-docs/src/main/sphinx/admin/properties-session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,22 @@ Queries with higher priority are scheduled first than the ones with lower priori

Use to configure how long a query can be queued before it is terminated.

The corresponding configuration property is :ref:`admin/properties:\`\`query.max-queued-time\`\``.
The corresponding configuration property is :ref:`admin/properties:\`\`query.max-queued-time\`\``.

Materialized View Properties
----------------------------

``legacy_materialized_views``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* **Type:** ``boolean``
* **Default value:** ``true``

Use legacy materialized views implementation. Set to ``false`` to enable the new materialized
views implementation.

The corresponding configuration property is :ref:`admin/properties:\`\`experimental.legacy-materialized-views\`\``.

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.
21 changes: 20 additions & 1 deletion presto-docs/src/main/sphinx/admin/properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1224,4 +1224,23 @@ for cross-cluster retry operations.
Comma-separated list of error codes that allow cross-cluster retry. When a query
fails with one of these error codes, it can be automatically retried on a backup
cluster if a retry URL is provided. Available error codes include standard Presto
error codes such as ``REMOTE_TASK_ERROR``, ``CLUSTER_OUT_OF_MEMORY``, etc.
error codes such as ``REMOTE_TASK_ERROR``, ``CLUSTER_OUT_OF_MEMORY``, etc.

Materialized View Properties
----------------------------

``experimental.legacy-materialized-views``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* **Type:** ``boolean``
* **Default value:** ``true``

Use legacy materialized views implementation. Set to ``false`` to enable materialized
views with security modes (DEFINER and INVOKER), automatic query rewriting, and
freshness tracking.

The corresponding session property is :ref:`admin/properties-session:\`\`legacy_materialized_views\`\``.

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.
4 changes: 4 additions & 0 deletions presto-docs/src/main/sphinx/sql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This chapter describes the SQL syntax used in Presto.
sql/create-table
sql/create-table-as
sql/create-view
sql/create-materialized-view
sql/deallocate-prepare
sql/delete
sql/describe
Expand All @@ -30,13 +31,15 @@ This chapter describes the SQL syntax used in Presto.
sql/drop-schema
sql/drop-table
sql/drop-view
sql/drop-materialized-view
sql/execute
sql/explain
sql/explain-analyze
sql/grant
sql/grant-roles
sql/insert
sql/prepare
sql/refresh-materialized-view
sql/reset-session
sql/revoke
sql/revoke-roles
Expand All @@ -50,6 +53,7 @@ This chapter describes the SQL syntax used in Presto.
sql/show-create-schema
sql/show-create-table
sql/show-create-view
sql/show-create-materialized-view
sql/show-functions
sql/show-grants
sql/show-role-grants
Expand Down
68 changes: 68 additions & 0 deletions presto-docs/src/main/sphinx/sql/create-materialized-view.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
========================
CREATE MATERIALIZED VIEW
========================

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.

To enable, set :ref:`admin/properties:\`\`experimental.legacy-materialized-views\`\`` = ``false``
in configuration properties.

Synopsis
--------

.. code-block:: none

CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] view_name
[ COMMENT 'string' ]
[ WITH ( property_name = expression [, ...] ) ]
AS query

Description
-----------

Create a new materialized view of a :doc:`select` query. The materialized view physically stores
the query results, unlike regular views which are virtual. Queries can read pre-computed results
instead of re-executing the underlying query.

The optional ``IF NOT EXISTS`` clause causes the materialized view to be created only if it does
not already exist.

The optional ``COMMENT`` clause stores a description of the materialized view in the metastore.

The optional ``WITH`` clause specifies connector-specific properties. Connector properties vary by
connector implementation. Consult connector documentation for supported properties.

Examples
--------

Create a materialized view with daily aggregations::

CREATE MATERIALIZED VIEW daily_sales AS
SELECT date_trunc('day', order_date) AS day,
region,
SUM(amount) AS total_sales,
COUNT(*) AS order_count
FROM orders
GROUP BY date_trunc('day', order_date), region


Create a materialized view with connector properties::

CREATE MATERIALIZED VIEW partitioned_sales
WITH (
partitioned_by = ARRAY['year', 'month']
)
AS
SELECT year(order_date) AS year,
month(order_date) AS month,
SUM(amount) AS total_sales
FROM orders
GROUP BY year(order_date), month(order_date)

See Also
--------

:doc:`drop-materialized-view`, :doc:`refresh-materialized-view`,
:doc:`show-create-materialized-view`, :doc:`/admin/materialized-views`
42 changes: 42 additions & 0 deletions presto-docs/src/main/sphinx/sql/drop-materialized-view.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
=====================
DROP MATERIALIZED VIEW
=====================

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.

To enable, set :ref:`admin/properties:\`\`experimental.legacy-materialized-views\`\`` = ``false``
in configuration properties.

Synopsis
--------

.. code-block:: none

DROP MATERIALIZED VIEW [ IF EXISTS ] view_name

Description
-----------

Drop an existing materialized view and delete its stored data.

The optional ``IF EXISTS`` clause causes the statement to succeed even if the materialized view
does not exist.

Examples
--------

Drop the materialized view ``daily_sales``::

DROP MATERIALIZED VIEW daily_sales

Drop the materialized view if it exists::

DROP MATERIALIZED VIEW IF EXISTS daily_sales

See Also
--------

:doc:`create-materialized-view`, :doc:`refresh-materialized-view`,
:doc:`show-create-materialized-view`, :doc:`/admin/materialized-views`
36 changes: 36 additions & 0 deletions presto-docs/src/main/sphinx/sql/refresh-materialized-view.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
========================
REFRESH MATERIALIZED VIEW
========================

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.

To enable, set :ref:`admin/properties:\`\`experimental.legacy-materialized-views\`\`` = ``false``
in configuration properties.

Synopsis
--------

.. code-block:: none

REFRESH MATERIALIZED VIEW view_name

Description
-----------

Refresh the data stored in a materialized view by re-executing the view query against the base
tables.

Examples
--------

Refresh a materialized view::

REFRESH MATERIALIZED VIEW daily_sales

See Also
--------

:doc:`create-materialized-view`, :doc:`drop-materialized-view`,
:doc:`show-create-materialized-view`, :doc:`/admin/materialized-views`
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
============================
SHOW CREATE MATERIALIZED VIEW
============================

.. warning::

Materialized views are experimental. The SPI and behavior may change in future releases.

To enable, set :ref:`admin/properties:\`\`experimental.legacy-materialized-views\`\`` = ``false``
in configuration properties.

Synopsis
--------

.. code-block:: none

SHOW CREATE MATERIALIZED VIEW view_name

Description
-----------

Show the SQL statement that creates the specified materialized view.

Examples
--------

Show the SQL for the ``daily_sales`` materialized view::

SHOW CREATE MATERIALIZED VIEW daily_sales

See Also
--------

:doc:`create-materialized-view`, :doc:`drop-materialized-view`,
:doc:`refresh-materialized-view`, :doc:`/admin/materialized-views`
Loading