Skip to content

Commit 0144ebd

Browse files
authored
IGNITE-28725 Document CREATE TABLE on existing caches (#13182)
Codex co-authored-by: Dmitriy Pavlov <dpavlov@apache.org>
1 parent 3087d27 commit 0144ebd

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

docs/_docs/SQL/schemas.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CREATE TABLE City (
8585
) WITH "backups=1, CACHE_NAME=City";
8686
----
8787

88-
See the link:sql-reference/ddl#create-table[CREATE TABLE] page for more details.
88+
See the link:sql-reference/ddl#create-table[CREATE TABLE] page for more details, including creating a table on an existing cache.
8989

9090
If you do not use this parameter, the cache name is defined in the following format (in capital letters):
9191

@@ -140,4 +140,4 @@ cache.put(2, invalidPerson); // CacheException wrapping IgniteSQLException when
140140

141141
With the default configuration (validation disabled for non-indexed columns), the `put` above succeeds even though the stored `BinaryObject` does not match the SQL schema. Turning on validation causes Ignite to reject the update, protecting the table from malformed records.
142142

143-
Enable the option when you need stronger guarantees that dynamic or user-provided data cannot break the table definition, and keep it disabled when the overhead of additional checks outweighs the risk of incorrect data.
143+
Enable the option when you need stronger guarantees that dynamic or user-provided data cannot break the table definition, and keep it disabled when the overhead of additional checks outweighs the risk of incorrect data.

docs/_docs/sql-reference/ddl.adoc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ This page encompasses all data definition language (DDL) commands supported by I
2121

2222
== CREATE TABLE
2323

24-
The command creates a new Ignite cache and defines a SQL table on top of it. The underlying cache stores the data in
25-
the form of key-value pairs while the table allows processing the data with SQL queries.
24+
The command defines a SQL table on top of an Ignite cache. The underlying cache stores the data in the form of
25+
key-value pairs while the table allows processing the data with SQL queries. By default, Ignite creates a new cache for
26+
the table. If `CACHE_NAME` points to an existing cache, Ignite defines the SQL table on top of that cache.
2627

2728
The table will reside in the link:SQL/schemas[Schema] specified in the connection parameters. If no schema is specified,
2829
the `PUBLIC` will be used as a default.
@@ -57,8 +58,9 @@ Parameters:
5758
sets the write synchronization mode for the underlying cache. If neither this nor the `TEMPLATE` parameter is set, then the cache is created with `FULL_SYNC` mode enabled.
5859
** `CACHE_GROUP=<group name>` - specifies the link:configuring-caches/cache-groups[group name] the underlying cache belongs to.
5960
** `AFFINITY_KEY=<affinity key column name>` - specifies an link:data-modeling/affinity-collocation[affinity key] name which is a column of the `PRIMARY KEY` constraint.
60-
** `CACHE_NAME=<custom name of the new cache>` - the name of the underlying cache created by the command,
61-
or the `SQL_{SCHEMA_NAME}_{TABLE}` format will be used if the parameter not specified.
61+
** `CACHE_NAME=<cache name>` - the name of the underlying cache. If the cache does not exist, it is created by the command.
62+
If the cache already exists, Ignite tries to define the table on top of it.
63+
If the parameter is not specified, the `SQL_{SCHEMA_NAME}_{TABLE}` format is used for the new cache name.
6264
** `DATA_REGION=<existing data region name>` - name of the link:memory-configuration/data-regions[data region] where table entries should be stored. By default, Ignite stores all the data in a default region.
6365
** `PARALLELISM=<number of SQL execution threads>` - SQL queries are executed by a single thread on each node by default, but certain scenarios can benefit from multi-threaded execution, see link:perf-and-troubleshooting/sql-tuning#query-parallelism[Query Parallelism] for details.
6466
** `KEY_TYPE=<custom name of the key type>` - sets the name of the custom key type that is used from the key-value APIs in Ignite. The name should correspond to a Java, .NET, or C++ class, or it can be a random one if link:data-modeling/data-modeling#binary-object-format[BinaryObjects] is used instead of a custom class. The number of fields and their types in the custom key type has to correspond to the `PRIMARY KEY`. Refer to the <<Use non-SQL API>> section below for more details.
@@ -118,6 +120,26 @@ CREATE TABLE IF NOT EXISTS Person (
118120
) WITH "template=partitioned,backups=1,affinity_key=city_id,CACHE_NAME=Person,KEY_TYPE=PersonKey,VALUE_TYPE=PersonValue";
119121
----
120122

123+
=== Create Table on an Existing Cache
124+
125+
If `CACHE_NAME` points to an existing cache, Ignite adds only SQL metadata to that cache. This is allowed only when the
126+
cache does not already have query entities, for example from `CacheConfiguration.setQueryEntities(...)` or
127+
`CacheConfiguration.setIndexedTypes(...)`.
128+
129+
When the existing cache has a SQL schema configured, the table must be created in the same schema. If the schema does not
130+
match, the command fails with an `Invalid schema` error.
131+
132+
[source,sql]
133+
----
134+
CREATE TABLE my_schema.Person (
135+
id INT PRIMARY KEY,
136+
name VARCHAR
137+
) WITH "CACHE_NAME=PersonCache";
138+
----
139+
140+
Cache creation parameters such as `TEMPLATE`, `BACKUPS`, `CACHE_GROUP`, `DATA_REGION`, `ATOMICITY`,
141+
`WRITE_SYNCHRONIZATION_MODE`, and other cache configuration options are not applied to an existing cache.
142+
121143

122144
=== Use non-Upper Case Columns
123145

0 commit comments

Comments
 (0)