blob: 6824746cb4801c9b1d6dd85929400d6d2b80238d [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
= SQL Transactions
:javaSourceFile: {javaCodeDir}/SqlTransactions.java
IMPORTANT: Support for SQL transactions is currently in the beta stage. For production use, consider key-value transactions.
== Overview
SQL Transactions are supported for caches that use the `TRANSACTIONAL_SNAPSHOT` atomicity mode. The `TRANSACTIONAL_SNAPSHOT` mode is the implementation of multiversion concurrency control (MVCC) for Ignite caches. For more information about MVCC and current limitations, visit the link:transactions/mvcc[Multiversion Concurrency Control] page.
See the link:sql-reference/transactions[Transactions] page for the transaction syntax supported by Ignite.
== Enabling MVCC
To enable MVCC for a cache, use the `TRANSACTIONAL_SNAPSHOT` atomicity mode in the cache configuration. If you create a table with the `CREATE TABLE` command, specify the atomicity mode as a parameter in the `WITH` part of the command:
[tabs]
--
tab:SQL[]
[source,sql]
----
CREATE TABLE Person WITH "ATOMICITY=TRANSACTIONAL_SNAPSHOT"
----
tab:XML[]
[source,xml]
----
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="myCache"/>
<property name="atomicityMode" value="TRANSACTIONAL_SNAPSHOT"/>
</bean>
</property>
</bean>
----
tab:Java[]
[source,java]
----
include::{javaSourceFile}[tag=enable,indent=0]
----
tab:C#/.NET[]
[source,csharp]
----
include::code-snippets/dotnet/SqlTransactions.cs[tag=mvcc,indent=0]
----
tab:C++[unsupported]
--
== Limitations
=== Cross-Cache Transactions
The `TRANSACTIONAL_SNAPSHOT` mode is enabled per cache and does not permit caches with different atomicity modes within one transaction. Thus, if you want to cover multiple tables in one SQL transaction, all tables must be created with the `TRANSACTIONAL_SNAPSHOT` mode.
=== Nested Transactions
Ignite supports three modes of handling nested SQL transactions that can be enabled via a JDBC/ODBC connection parameter.
[source,sql]
----
jdbc:ignite:thin://127.0.0.1/?nestedTransactionsMode=COMMIT
----
When a nested transaction occurs within another transaction, the system behavior depends on the `nestedTransactionsMode` parameter:
- `ERROR` When the nested transaction is encountered, an error is thrown and the enclosing transaction is rolled back. This is the default behavior.
- `COMMIT` The enclosing transaction is committed; the nested transaction starts and is committed when its COMMIT statement is encountered. The rest of the statements in the enclosing transaction are executed as implicit transactions.
- `IGNORE` DO NOT USE THIS MODE. The beginning of the nested transaction is ignored, statements within the nested transaction will be executed as part of the enclosing transaction, and all changes will be committed with the commit of the nested transaction. The subsequent statements of the enclosing transaction will be executed as implicit transactions.