You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/guides/55-performance/01-virtual-column.md
+53-33Lines changed: 53 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -7,33 +7,49 @@ import EEFeature from '@site/src/components/EEFeature';
7
7
8
8
<EEFeaturefeatureName='VIRTUAL COLUMN'/>
9
9
10
-
A virtual column is a construct formed by extracting nested fields within [Variant](/sql/sql-reference/data-types/variant) data and storing that data in separate storage files. Consider using virtual columns when you regularly query specific nested fields within Variant data to realize the following benefits:
10
+
# Virtual Columns in Databend: Accelerating Queries on Semi-Structured Data
11
11
12
-
-**Accelerated Query Processing**: Virtual columns streamline the querying process by eliminating the need to traverse the entire nested structure to locate the desired data. Direct data retrieval from virtual columns parallels the process of accessing regular columns, resulting in a significant acceleration of query execution.
12
+
Virtual columns in Databend provide a powerful and automatic way to significantly accelerate queries on semi-structured data, particularly data stored in the [Variant](/sql/sql-reference/data-types/variant) data type. This feature dynamically optimizes data access, leading to faster query execution and reduced resource consumption.
13
13
14
-
-**Reduced Memory Usage**: Variant data often includes numerous internal fields, and reading all of them can lead to substantial memory consumption. By transitioning to reading virtual columns, there is a notable reduction in memory usage, mitigating the risk of potential memory overflows.
14
+
## Overview
15
+
16
+
When working with nested data structures within `VARIANT` columns, accessing specific data points can be a performance bottleneck. Databend's virtual columns address this by automatically identifying and optimizing nested fields. Instead of repeatedly traversing the entire nested structure, virtual columns enable direct data retrieval, similar to accessing regular columns.
17
+
18
+
Databend automatically detects nested fields within `VARIANT` columns during data ingestion. If a field meets a certain threshold for presence, it's materialized as a virtual column in the background, ensuring that data is readily available for optimized querying. This process is entirely automatic, requiring no manual configuration or intervention.
15
19
16
20

17
21
18
-
## Managing Virtual Columns
22
+
## Performance Benefits
23
+
24
+
***Significant Query Acceleration:** Virtual columns dramatically reduce query execution time by enabling direct access to nested fields. This eliminates the overhead of traversing complex JSON structures for each query.
25
+
***Reduced Resource Consumption:** By materializing only the necessary nested fields, virtual columns minimize memory consumption during query processing. This leads to more efficient resource utilization and improved overall system performance.
26
+
***Automatic Optimization:** Databend automatically identifies and materializes fields as virtual columns. The query optimizer then automatically rewrites queries to utilize these virtual columns when accessing data within the `VARIANT` column.
27
+
***Transparent Operation:** The creation and management of virtual columns are entirely transparent to the user. Queries are automatically optimized without requiring any changes to the query syntax or data loading process. The query optimizer handles the rewriting of queries to leverage virtual columns.
28
+
29
+
## How it Works
19
30
20
-
Databend provides a variety of commands to manage virtual columns. For details, see [VIRTUAL COLUMN](/sql/sql-commands/ddl/virtual-column/).
31
+
1.**Data Ingestion:** When data containing `VARIANT` columns is ingested, Databend analyzes the structure of the JSON data.
32
+
2.**Field Presence Check:** Databend checks if a nested field meets a certain threshold for presence.
33
+
3.**Virtual Column Materialization:** If the field presence threshold is met, the system automatically materializes the field as a virtual column in the background.
34
+
4.**Query Optimization:** When a query accesses a nested field within a `VARIANT` column, the query optimizer automatically rewrites the query to use the corresponding virtual column for faster data retrieval.
35
+
36
+
## Important Considerations
37
+
38
+
***Overhead:** While virtual columns generally improve query performance, they do introduce some storage and maintenance overhead. Databend automatically balances the benefits of virtual columns against this overhead to ensure optimal performance.
39
+
***Experimental Feature:** Virtual columns are currently an experimental feature. They are disabled by default. To enable virtual columns, you must set the `enable_experimental_virtual_column` setting to `1`:
40
+
***Automatic Refresh:** Virtual columns will be refreshed automatically after inserting data. If you don't want to generate virtual column data automatically, you can set `enable_refresh_virtual_column_after_write` to `0` to disable the generation of virtual columns. Asynchronous refresh can be done by using the refresh virtual column command. For details, see [REFRESH VIRTUAL COLUMN](/sql/sql-commands/ddl/virtual-column/refresh-virtual-column).
41
+
***Show Virtual columns:** You can view information about virtual columns through the [SHOW VIRTUAL COLUMNS](/sql/sql-commands/ddl/virtual-column/show-virtual-columns) command, and you can view information about virtual column metas through the [FUSE_VIRTUAL_COLUMN](/sql/sql-functions/system-functions/fuse_virtual_column) system function.
21
42
22
43
## Usage Examples
23
44
24
45
This example demonstrates the practical use of virtual columns and their impact on query execution:
25
46
26
47
```sql
48
+
SET enable_experimental_virtual_column=1;
49
+
27
50
-- Create a table named 'test' with columns 'id' and 'val' of type Variant.
28
51
CREATETABLEtest(id int, val variant);
29
52
30
-
-- Create virtual columns for specific elements in the 'val' column.
31
-
CREATE VIRTUAL COLUMN (
32
-
val ['name'], -- Extract the 'name' field.
33
-
val ['tags'] [0], -- Extract the first element in the 'tags' array.
34
-
val ['pricings'] [0] ['type'] -- Extract the 'type' field from the first pricing in the 'pricings' array.
35
-
) FOR test;
36
-
37
53
-- Insert sample records into the 'test' table with Variant data.
38
54
INSERT INTO
39
55
test
@@ -65,8 +81,7 @@ INSERT INTO test SELECT * FROM test;
65
81
INSERT INTO test SELECT*FROM test;
66
82
INSERT INTO test SELECT*FROM test;
67
83
68
-
-- Refresh the virtual columns
69
-
REFRESH VIRTUAL COLUMN FOR test;
84
+
-- Show the virtual columns
70
85
71
86
-- Explain the query execution plan for selecting specific fields from the table.
0 commit comments