<Header icon={<img src="/docs/logos/motherduck.svg" className="w-9 h-9 inline" />}>MotherDuck (DuckDB)</Header>

DuckDB-powered cloud data warehouse scaling to terabytes with ease.

## Features

| Feature                                       | Supported |
|-----------------------------------------------|-----------|
| [Batch Mode](#batch-mode)                     | ✅         |
| [Stream Mode](#stream-mode)                   | ✅         |
| [Deduplication](#deduplication)               | ✅         |
| [Queries Optimization](#queries-optimization) | ✅         |

## Configuration

<DestinationConfiguration type="duckdb" />

## Advanced: Implementation Details

This section describes how Jitsu implements various modes and features for DuckDB.

### Batch Mode

<details>
<summary>Algorithm</summary>

```sql
-- Jitsu collects events batches in tmp file on file system.
ATTACH ':memory:' as jitsu_memdb
INSERT into jitsu_memdb.tmp_table
INSERT into target_table select from jitsu_memdb.tmp_table
```
</details>

### Stream Mode

`INSERT INTO target_table (...) VALUES (..)`

### Deduplication

For batch mode the following algorithm is used:
<details>
<summary>Algorithm</summary>

```sql
-- Jitsu collects events batches in tmp file on file system.
-- Deduplicate rows in tmp file
ATTACH ':memory:' as jitsu_memdb
INSERT into jitsu_memdb.tmp_table
INSERT OR REPLACE into target_table select from jitsu_memdb.tmp_table
```
</details>

For stream mode:

`INSERT OR REPLACE INTO target_table (...) VALUES (..)`

### Queries Optimization

**Timestamp** connection setting is used to optimize SELECT queries.

Regular index is created on specified timestamp column.