21190 Commits

Author SHA1 Message Date
Pekka Enberg
12ca4e2f6a Merge 'core: resolve group by and order by collation from expressions' from Paris Kasidiaris
Make GROUP BY and ORDER BY use BINARY for computed keys by default,
matching SQLite. Direct columns keep their declared collation, and
explicit COLLATE still applies.

Use the existing comparison resolver for GROUP BY and ORDER BY keys so
the whole expression determines the rule. Add two SQL regression tests,
including ORDER BY with and without LIMIT.

We found this during SQLite compatibility checks for our OpenTelemetry
server, which uses Turso for storage. In the example below, `main`
inherits the host’s NOCASE rule when building the URL. It merges two
`/help/` failures with one `/Help/` failure, causing a false positive
alert. SQLite and this patch keep them separate.

Both new regression tests fail on main; all 122 collation cases pass on
this branch.

## Real-world example

The http_requests table records HTTP requests. We want to find URLs that
returned 404 at least three times.

### Question

**Which URLs returned 404 at least 3 times**?

### `requests` table

| id | received_at | host | path | status |
|---|---|---|---|---|
| 101 | 2026-10-08T09:10:00Z | fakos.dev | /docs/ | 200 |
| 102 | 2026-10-08T09:35:00Z | fakos.dev | /docs/quickstart/ | 200 |
| 103 | 2026-10-08T11:20:00Z | fakos.dev | /help/ | 404 |
| 104 | 2026-10-08T11:21:00Z | fakos.dev | /Help/ | 404 |
| 105 | 2026-10-08T12:05:00Z | fakos.dev | /help/ | 404 |
| 106 | 2026-10-08T12:10:00Z | fakos.dev | /docs/getting-started/ | 404
|
| 107 | 2026-10-08T12:15:00Z | fakos.dev | /docs/getting-started/ | 404
|
| 108 | 2026-10-08T12:20:00Z | fakos.dev | /docs/getting-started/ | 404
|

> [!IMPORTANT]
>
> `host` uses NOCASE. The full URL must keep path case. `endpoint` names
that URL in SELECT, GROUP BY, and ORDER BY.

### Query (`query.sql`)

```sql
SELECT 'https://' || host || path AS endpoint, count(*) AS not_found
FROM http_requests
WHERE status = 404
GROUP BY endpoint
HAVING count(*) >= 3
ORDER BY not_found DESC, endpoint;
```

### ❌ turso - `main`

| endpoint | not_found |
|---|---|
| https://fakos.dev/docs/getting-started/ | 3 |
| https://fakos.dev/help/ | 3 |

Main wrongly combines `/help/` and `/Help/` into three failures.

### ✅ sqlite and turso `group-order-by-default-collation`

| endpoint | not_found |
|---|---|
| https://fakos.dev/docs/getting-started/ | 3 |

Only `/docs/getting-started/` failed three times.

## Steps to reproduce

### 1 - Create `requests_table.sql`

```sql
CREATE TABLE http_requests(
    id INTEGER PRIMARY KEY,
    received_at TEXT,
    host TEXT COLLATE NOCASE,
    path TEXT,
    status INTEGER
);

INSERT INTO http_requests VALUES
    (101, '2026-10-08T09:10:00Z', 'fakos.dev', '/docs/', 200),
    (102, '2026-10-08T09:35:00Z', 'fakos.dev', '/docs/quickstart/', 200),
    (103, '2026-10-08T11:20:00Z', 'fakos.dev', '/help/', 404),
    (104, '2026-10-08T11:21:00Z', 'fakos.dev', '/Help/', 404),
    (105, '2026-10-08T12:05:00Z', 'fakos.dev', '/help/', 404),
    (106, '2026-10-08T12:10:00Z', 'fakos.dev', '/docs/getting-started/', 404),
    (107, '2026-10-08T12:15:00Z', 'fakos.dev', '/docs/getting-started/', 404),
    (108, '2026-10-08T12:20:00Z', 'fakos.dev', '/docs/getting-started/', 404);
```

### 2 - Run `requests_table.sql` and `query.sql` in SQLite for reference

```
sqlite3 :memory: ".read requests_table.sql" ".read query.sql"
```

### 3 - Run `requests_table.sql` and `query.sql` in Turso (`main`)

```
cargo run -q --bin tursodb -- :memory: -q -m list "$(cat requests_table.sql query.sql)"
```

We used AI agents (mostly Codex) to trace the incorrect collation lookup
and prepare the smallest possible Rust patch.

We have reviewed both end-to-end SQL behavior and all code changes
included in this patch.

---

**UPDATE**: Reviewing the snapshot update commit is easier with
whitespace disabled: https://github.com/tursodatabase/turso/pull/9655/ch
anges/42a4c81f9a8a5f514f2d544b8fa6e3e16d01ca27?w=1

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #9655
2026-10-15 12:28:26 +03:00
Jussi Saurio
d77a608e0b Merge 'core/json: leave the document unchanged when json_insert targets the root' from app/turso-github-handyman
`json_insert` and `jsonb_insert` with the path `$` replaced the whole
document with the new value. SQLite leaves the document unchanged,
because json_insert only adds values that don't exist yet and the root
always exists.

```sql
SELECT json_insert('{"a":2}', '$', 1);
-- before: 1
-- after (and SQLite): {"a":2}
SELECT json_insert(NULL, '$', 123);
-- before: 123
-- after (and SQLite): NULL
```

`navigate_to_segment` returned the root segment as a target without
checking the operation mode, so `InsertOperation::execute` overwrote the
root in insert-only mode. Now the root counts as an existing value: when
the mode doesn't allow replacing, navigation fails the same way it does
for an existing array entry, and the insert is skipped. When `$` is only
the start of a longer path, it is navigated in upsert mode, so inserts
like `$.b` work as before. `json_set` and `json_replace` still replace
the root.

Fixes #9924

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9949
2026-10-15 12:24:29 +03:00
Pekka Enberg
a820079e8e Turso 0.9.0-pre.1 2026-10-15 12:17:20 +03:00
Pekka Enberg
5507fa4d5e Merge 'core/schema: keep COLLATE and DESC in UNIQUE and PRIMARY KEY table constraints' from teleivo
`ALTER TABLE` rewrites the stored `CREATE TABLE` text with
`BTreeTable::to_sql`, which dropped `COLLATE` from table-level `UNIQUE
(...)` and `PRIMARY KEY (...)` constraints and `DESC` from `UNIQUE
(...)`. `ADD COLUMN` and `DROP COLUMN` both go through it. After the
database is opened again, the constraint's automatic index is searched
as `BINARY` and ascending while its b-tree is sorted by the original
collation and order, so duplicates are accepted.

* write the collation of each constraint column, for `UNIQUE` and
`PRIMARY KEY`
* write `DESC` for `UNIQUE` columns. `PRIMARY KEY (a DESC)` already kept
it: it is written inline as `a TEXT PRIMARY KEY DESC`, which is the same
constraint, not `a TEXT PRIMARY KEY` as the issue says
* keep a single-column primary key with a collation as a table
constraint. Writing it inline as `a PRIMARY KEY COLLATE NOCASE` would
give the column itself that collation, which changes every comparison on
`a`

Not covered: `NULLS FIRST/LAST` in both constraints is still dropped,
and the constraint order problem from #8704 is unchanged.

Fixes #8702

Closes #9635
2026-10-15 12:16:14 +03:00
Jussi Saurio
384dffa46d Merge 'core/vdbe: store -0.0 as 0.0 when applying REAL affinity' from app/turso-github-handyman
SQLite stores a whole-number value in a REAL column as an integer, so
-0.0 is written as 0 and read back as +0.0. Turso stored the f64 with
its sign, which showed in math functions, JSON built from the value, and
to API users.

```sql
CREATE TABLE r(x REAL);
INSERT INTO r VALUES (-0.0);
SELECT atan2(0, x) FROM r;
-- before: 3.14159265358979
-- after:  0.0 (same as SQLite)
```

REAL affinity now turns -0.0 into +0.0. For every other whole number
this gives the same value as SQLite's integer round trip. The change
covers both places REAL affinity is applied: `apply_affinity_char`
(INSERT, UPDATE, column DEFAULT, index keys, array elements) and
`Affinity::convert` (the default value of a column added with `ALTER
TABLE ADD COLUMN`). Columns with no affinity still keep -0.0, as in
SQLite.

`negative-zero-float-equality` in `array-edge-cases.sqltest` expected
`{0.0}` and `{-0.0}` in a `real[]` column to be two distinct values.
Both already displayed as `{0.0}`, and PostgreSQL also counts them as
one, so the expected value is now 1.

Fixes #9889

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9914
2026-10-15 12:16:10 +03:00
Pekka Enberg
6a018b0755 Merge 'examples/react-native: update metro to 0.83.8 to drop image-size' from Pekka Enberg
Fixes Dependabot alert #547: `image-size` 1.2.1 in `examples/react-
native/package-lock.json` is affected by GHSA for the ICNS parser
infinite loop (fixed in 2.0.3). Dependabot could not update it because
`metro` 0.83.5 requires `image-size ^1.0.2`.

`metro` 0.83.8 dropped the `image-size` dependency entirely and fits the
existing `^0.83.3` range from `@react-native/community-cli-plugin`, so
updating the metro packages in the lockfile removes the vulnerable
package. No override is needed and `package.json` is unchanged.

Lockfile changes:
- 15 `metro*` packages: 0.83.5 -> 0.83.8
- `hermes-parser` (nested under metro): 0.33.3 -> 0.35.0
- `negotiator` (nested under metro): 1.0.0 -> 1.1.0
- `image-size` and `queue` removed

Validation: `npm ci` in `examples/react-native` succeeds and `npm ls
image-size` no longer resolves it from the example's own tree.

Closes #9948
2026-10-15 11:42:44 +03:00
Pekka Enberg
7f5ecaf7ee Merge 'build(deps): bump source-map-js from 1.2.1 to 1.2.2 in /bindings/javascript' from app/dependabot
Bumps [source-map-js](https://github.com/7rulnik/source-map-js) from
1.2.1 to 1.2.2. <details> <summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/7rulnik/source-map-
js/releases">source-map-js's releases</a>.</em></p> <blockquote>
<h2>v1.2.2</h2> <ul> <li> <p>Fix crash when executing in browser with
CSP script-src that don't permit unsafe-eval (<a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/29">#29</a>) <a
href="https://github.com/xfournet"><code>@​xfournet</code></a></p> </li>
<li> <p>Fix denial of service from malicious indexed source maps
(CVE-2026-93749) (<a href="https://redirect.github.com/7rulnik/source-
map-js/pull/79">#79</a>)</p> <p>Reported by <a
href="https://github.com/waydeshi"><code>@​waydeshi</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/issues/76">#76</a>. A fix was also proposed by <a
href="https://github.com/aniebiet"><code>@​aniebiet</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/78">#78</a>.</p> </li> </ul> </blockquote> </details> <details>
<summary>Changelog</summary> <p><em>Sourced from <a
href="https://github.com/7rulnik/source-map-
js/blob/main/CHANGELOG.md">source-map-js's changelog</a>.</em></p>
<blockquote> <h2>1.2.2</h2> <ul> <li> <p>Fix crash when executing in
browser with CSP script-src that don't permit unsafe-eval (<a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/29">#29</a>) <a
href="https://github.com/xfournet"><code>@​xfournet</code></a></p> </li>
<li> <p>Fix denial of service from malicious indexed source maps
(CVE-2026-93749) (<a href="https://redirect.github.com/7rulnik/source-
map-js/pull/79">#79</a>)</p> <p>Reported by <a
href="https://github.com/waydeshi"><code>@​waydeshi</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/issues/76">#76</a>. A fix was also proposed by <a
href="https://github.com/aniebiet"><code>@​aniebiet</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/78">#78</a>.</p> </li> </ul> </blockquote> </details> <details>
<summary>Commits</summary> <ul> <li><a
href="https://github.com/7rulnik/source-map-js/commit/0a1d334fd1e55a47df
97fcd60a7915d46df3b08a"><code>0a1d334</code></a> 1.2.2</li> <li><a
href="https://github.com/7rulnik/source-map-js/commit/4c6fa26d77419bd8e4
8ec92844866cce7d9ae739"><code>4c6fa26</code></a> Update changelog</li>
<li><a href="https://github.com/7rulnik/source-map-js/commit/cf7658058ce
eaa8619d5ae0ec90be6905209d016"><code>cf76580</code></a> Fix denial of
service from malicious indexed source maps (CVE-2026-93749) (<a
href="https://redirect.github.com/7rulnik/source-map-
js/issues/79">#79</a>)</li> <li><a
href="https://github.com/7rulnik/source-map-js/commit/7899a86615c630f4fc
220273ff9fe2e8e49a56df"><code>7899a86</code></a> Fix crash when
executing browser with CSP script-src that don't permit unsafe...</li>
<li>See full diff in <a href="https://github.com/7rulnik/source-map-
js/compare/v1.2.1...v1.2.2">compare view</a></li> </ul> </details> <br
/>

[![Dependabot compatibility score](https://dependabot-
badges.githubapp.com/badges/compatibility_score?dependency-name=source-
map-js&package-manager=npm_and_yarn&previous-version=1.2.1&new-
version=1.2.2)](https://docs.github.com/en/github/managing-security-
vulnerabilities/about-dependabot-security-updates#about-compatibility-
scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end)

---

<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/tursodatabase/turso/network/alerts).

</details>

Closes #9947
2026-10-15 11:42:29 +03:00
Turso Agent
3aa0ef120e core/json: leave the document unchanged when json_insert targets the root
Fixes #9924
2026-10-15 08:41:32 +00:00
Pekka Enberg
5b4b9515fd Merge 'bindings/python: fix sqlite+aioturso on SQLAlchemy 2.0.46 and later' from Orthel Toralen
`create_async_engine("sqlite+aioturso:///...")` fails on SQLAlchemy
2.0.46 and later:

```python
AttributeError: 'AsyncAdapt_turso_dbapi' object has no attribute 'has_stop'
```

`AioTursoDialect` inherits from SQLAlchemy's `SQLiteDialect_aiosqlite`,
but it wraps connections in SQLAlchemy's generic
`AsyncAdapt_dbapi_connection`, not in the aiosqlite connection class.
SQLAlchemy 2.0.46 added two things to `SQLiteDialect_aiosqlite` that
only work with aiosqlite's DBAPI module and connection class:
- `__init__()` reads `dbapi.has_stop`. It uses the value to decide
whether the pool may call `terminate()` on connections that were
garbage-collected without being returned. `AsyncAdapt_turso_dbapi` has
no `has_stop` attribute, so creating the engine fails.
- `do_terminate()` calls `dbapi_connection.terminate()`. The pool calls
`do_terminate()` when it invalidates a connection, for example after
`conn.invalidate()` or a cancelled query, and when it recycles a
connection. `AsyncAdapt_dbapi_connection` has no `terminate()` method.
The pool logs the `AttributeError` and opens a new connection, but the
old turso connection is never closed and its worker thread keeps
running.

### This PR:
- Sets `has_stop = False` on `AsyncAdapt_turso_dbapi`, because
`turso.aio.Connection` has no `stop()` method. SQLAlchemy then sets
`has_terminate = False` and drops garbage-collected connections without
trying to close them, as it did on 2.0.45.
- Overrides `do_terminate()` on `AioTursoDialect` to call `close()`,
which is what `do_terminate()` did on 2.0.45. The pool calls
`do_terminate()` from inside SQLAlchemy's greenlet, so `close()` can
wait for turso's async close.
- Adds regression tests to `tests/test_sqlalchemy_async.py` for three
cases: creating a file-database engine, running a query and disposing
the engine; invalidating a connection; and cancelling a running query.
The last two tests check that the pool logs no errors and that no turso
worker threads are left after `dispose()`.
Every released pyturso version that includes the async dialect (0.6.0
and later) fails on SQLAlchemy 2.0.46 and later, including 2.1.x.

The SQLAlchemy tests already catch the crash, but CI never runs them:
`.github/workflows/python.yml` only runs the `test_database*.py` files,
and `uv.lock` locks SQLAlchemy at 2.0.45, the last version that works.
This PR does not change the CI workflow. Claude Code (Claude Opus 5.5)
checked the fix against the SQLAlchemy source, wrote the regression
tests and reviewed this description. The tests fail without the fix on
SQLAlchemy 2.0.46, 2.0.54 and 2.1.2, and pass with it on 2.0.45, 2.0.54
and 2.1.2.

Closes #9477
2026-10-15 11:32:45 +03:00
Pekka Enberg
65a7ebf9f1 Merge 'sdk-kit: find rc.exe through the registered Windows SDK' from
On MSVC targets, the `turso_sdk_kit` build script looks for `rc.exe`
only in `PATH` and under `%ProgramFiles(x86)%\Windows Kits\10\bin`. If
the Windows SDK is installed anywhere else (mine is in `D:\Windows
Kits\10`), the build panics:

```
rc.exe was not found in PATH and Windows SDK bin directory C:\Program Files (x86)\Windows Kits\10\bin could not be read: The system cannot find the path specified. (os error 3)
```

This breaks any project that pulls in `turso` on Windows, even as a
transitive dependency. I ran into it through `cubecl` (used by `burn`),
which uses `turso` for its on-disk cache.

This change keeps the `PATH` lookup. If that fails, the script now gets
the SDK location from `find_msvc_tools::find_windows_sdk`, which reads
it from the registry the same way `cc` does, and looks for `rc.exe` in
the SDK's bin directories for the host architecture. The registry also
points to the default install location, so I removed the old Program
Files lookup. `find-msvc-tools` is already in `Cargo.lock` through `cc`,
so nothing new gets downloaded. I added its licenses and a NOTICE entry
as described in CONTRIBUTING.md.

This doesn't touch the `windres` path for GNU targets, which is a
separate problem (#8689).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Closes #9500
2026-10-15 11:31:18 +03:00
Pekka Enberg
be31b611cd examples/react-native: update metro to 0.83.8 to drop image-size
Dependabot alert #547 flags image-size 1.2.1 in the react-native
example lockfile (GHSA: ICNS parser infinite loop, fixed in 2.0.3).
Dependabot cannot fix it on its own because metro 0.83.5 requires
image-size ^1.0.2.

metro 0.83.8 no longer depends on image-size at all and fits the
existing ^0.83.3 range from @react-native/community-cli-plugin, so
updating the metro packages in the lockfile removes the vulnerable
package without an override. package.json is unchanged.

Tests: `npm ci` in examples/react-native succeeds and `npm ls
image-size` no longer resolves it from the example's own tree.
2026-10-15 11:30:48 +03:00
dependabot[bot]
09163a05d7 build(deps): bump source-map-js in /bindings/javascript
Bumps [source-map-js](https://github.com/7rulnik/source-map-js) from 1.2.1 to 1.2.2.
- [Release notes](https://github.com/7rulnik/source-map-js/releases)
- [Changelog](https://github.com/7rulnik/source-map-js/blob/main/CHANGELOG.md)
- [Commits](https://github.com/7rulnik/source-map-js/compare/v1.2.1...v1.2.2)

---
updated-dependencies:
- dependency-name: source-map-js
  dependency-version: 1.2.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-15 08:29:08 +00:00
Pekka Enberg
d1a42470d8 Merge 'build(deps-dev): bump source-map-js from 1.2.1 to 1.2.2 in /examples/javascript/database-wasm-vite' from app/dependabot
Bumps [source-map-js](https://github.com/7rulnik/source-map-js) from
1.2.1 to 1.2.2. <details> <summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/7rulnik/source-map-
js/releases">source-map-js's releases</a>.</em></p> <blockquote>
<h2>v1.2.2</h2> <ul> <li> <p>Fix crash when executing in browser with
CSP script-src that don't permit unsafe-eval (<a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/29">#29</a>) <a
href="https://github.com/xfournet"><code>@​xfournet</code></a></p> </li>
<li> <p>Fix denial of service from malicious indexed source maps
(CVE-2026-93749) (<a href="https://redirect.github.com/7rulnik/source-
map-js/pull/79">#79</a>)</p> <p>Reported by <a
href="https://github.com/waydeshi"><code>@​waydeshi</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/issues/76">#76</a>. A fix was also proposed by <a
href="https://github.com/aniebiet"><code>@​aniebiet</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/78">#78</a>.</p> </li> </ul> </blockquote> </details> <details>
<summary>Changelog</summary> <p><em>Sourced from <a
href="https://github.com/7rulnik/source-map-
js/blob/main/CHANGELOG.md">source-map-js's changelog</a>.</em></p>
<blockquote> <h2>1.2.2</h2> <ul> <li> <p>Fix crash when executing in
browser with CSP script-src that don't permit unsafe-eval (<a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/29">#29</a>) <a
href="https://github.com/xfournet"><code>@​xfournet</code></a></p> </li>
<li> <p>Fix denial of service from malicious indexed source maps
(CVE-2026-93749) (<a href="https://redirect.github.com/7rulnik/source-
map-js/pull/79">#79</a>)</p> <p>Reported by <a
href="https://github.com/waydeshi"><code>@​waydeshi</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/issues/76">#76</a>. A fix was also proposed by <a
href="https://github.com/aniebiet"><code>@​aniebiet</code></a> in <a
href="https://redirect.github.com/7rulnik/source-map-
js/pull/78">#78</a>.</p> </li> </ul> </blockquote> </details> <details>
<summary>Commits</summary> <ul> <li><a
href="https://github.com/7rulnik/source-map-js/commit/0a1d334fd1e55a47df
97fcd60a7915d46df3b08a"><code>0a1d334</code></a> 1.2.2</li> <li><a
href="https://github.com/7rulnik/source-map-js/commit/4c6fa26d77419bd8e4
8ec92844866cce7d9ae739"><code>4c6fa26</code></a> Update changelog</li>
<li><a href="https://github.com/7rulnik/source-map-js/commit/cf7658058ce
eaa8619d5ae0ec90be6905209d016"><code>cf76580</code></a> Fix denial of
service from malicious indexed source maps (CVE-2026-93749) (<a
href="https://redirect.github.com/7rulnik/source-map-
js/issues/79">#79</a>)</li> <li><a
href="https://github.com/7rulnik/source-map-js/commit/7899a86615c630f4fc
220273ff9fe2e8e49a56df"><code>7899a86</code></a> Fix crash when
executing browser with CSP script-src that don't permit unsafe...</li>
<li>See full diff in <a href="https://github.com/7rulnik/source-map-
js/compare/v1.2.1...v1.2.2">compare view</a></li> </ul> </details> <br
/>

[![Dependabot compatibility score](https://dependabot-
badges.githubapp.com/badges/compatibility_score?dependency-name=source-
map-js&package-manager=npm_and_yarn&previous-version=1.2.1&new-
version=1.2.2)](https://docs.github.com/en/github/managing-security-
vulnerabilities/about-dependabot-security-updates#about-compatibility-
scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end)

---

<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/tursodatabase/turso/network/alerts).

</details>

Closes #9873
2026-10-15 11:25:16 +03:00
Pekka Enberg
192d7093a9 Merge 'build(deps-dev): bump shell-quote from 1.10.0 to 1.12.0 in /bindings/react-native' from app/dependabot
Bumps [shell-quote](https://github.com/ljharb/shell-quote) from 1.10.0
to 1.12.0. <details> <summary>Changelog</summary> <p><em>Sourced from <a
href="https://github.com/ljharb/shell-
quote/blob/main/CHANGELOG.md">shell-quote's changelog</a>.</em></p>
<blockquote> <h2><a href="https://github.com/ljharb/shell-
quote/compare/v1.11.0...v1.12.0">v1.12.0</a> - 2026-10-02</h2>
<h3>Fixed</h3> <ul> <li>[New] <code>parse</code>: support here-documents
(<code>&amp;lt;&amp;lt;</code>) <a
href="https://redirect.github.com/ljharb/shell-
quote/issues/31"><code>[#31](https://github.com/ljharb/shell-
quote/issues/31)</code></a></li> </ul> <h3>Commits</h3> <ul> <li>[New]
<code>parse</code>: support tab-stripping here-documents
(<code>&amp;lt;&amp;lt;-</code>) <a
href="https://github.com/ljharb/shell-quote/commit/dbfac376d4065d37539d3
abdb5e76847f93797d3"><code>dbfac37</code></a></li> <li>[New]
<code>parse</code>: support output process substitution
(<code>&amp;gt;(</code>) <a href="https://github.com/ljharb/shell-quote/
commit/20533154bb57809c80f55318b8493aef49505f4e"><code>2053315</code></a
></li> <li>[New] <code>parse</code>: support the <code>case</code> test-
next terminator (<code>;;&amp;</code>) <a
href="https://github.com/ljharb/shell-quote/commit/7d688b9bec1917a22cccd
4d4c887128a9c66e8a0"><code>7d688b9</code></a></li> <li>[New]
<code>parse</code>: support the <code>case</code> fall-through
terminator (<code>;&amp;</code>) <a
href="https://github.com/ljharb/shell-quote/commit/f27010ed04bcd925795b3
50afb1c49e36bbd1ba3"><code>f27010e</code></a></li> <li>[New]
<code>parse</code>: support redirecting output despite
<code>noclobber</code> (<code>&amp;gt;|</code>) <a
href="https://github.com/ljharb/shell-quote/commit/b78d19c14da6356cc12c4
6b3478203247ab8a295"><code>b78d19c</code></a></li> <li>[New]
<code>parse</code>: support opening a file for reading and writing
(<code>&amp;lt;&amp;gt;</code>) <a
href="https://github.com/ljharb/shell-quote/commit/21cc333eb0ce5bf094f59
5b7fdc01b3447ffd4b0"><code>21cc333</code></a></li> <li>[New]
<code>parse</code>: support redirecting stdout and stderr
(<code>&amp;&amp;gt;</code>) <a href="https://github.com/ljharb/shell-qu
ote/commit/6ad6cd215f89adcc29dd601e085fa54083c2f911"><code>6ad6cd2</code
></a></li> <li>[New] <code>parse</code>: support appending stdout and
stderr (<code>&amp;&amp;gt;&amp;gt;</code>) <a
href="https://github.com/ljharb/shell-quote/commit/90cde9cfd8af30fcb65e9
fd2cb2f9e181d3f103b"><code>90cde9c</code></a></li> <li>[Dev Deps] update
<code>@ljharb/eslint-config</code> <a
href="https://github.com/ljharb/shell-quote/commit/3a7b4ae3960c3ff441393
2e276c5b0ecb3a2b456"><code>3a7b4ae</code></a></li> </ul> <h2><a
href="https://github.com/ljharb/shell-
quote/compare/v1.10.0...v1.11.0">v1.11.0</a> - 2026-09-29</h2>
<h3>Fixed</h3> <ul> <li>[Refactor] <code>quote</code>: drop a replace
that can never match in the single-quote branch <a
href="https://redirect.github.com/ljharb/shell-
quote/issues/15"><code>[#15](https://github.com/ljharb/shell-
quote/issues/15)</code></a></li> <li>[New] <code>parse</code>: support
bash ANSI-C quoting (<code>$'...'</code>) <a
href="https://redirect.github.com/ljharb/shell-
quote/issues/32"><code>[#32](https://github.com/ljharb/shell-
quote/issues/32)</code></a></li> </ul> <h3>Commits</h3> <ul> <li>[Fix]
<code>quote</code>: reject line terminators in tokens after a
<code>comment</code> <a href="https://github.com/ljharb/shell-quote/comm
it/6002b2ed90c6b83095eb272b6b0adaf3a172b0bc"><code>6002b2e</code></a></l
i> <li>[Fix] <code>parse</code>: preserve text after special shell
parameters <a href="https://github.com/ljharb/shell-quote/commit/81b08a5
32e898a3627f9305fa13d643ffa82a9d3"><code>81b08a5</code></a></li>
<li>[Fix] <code>parse</code>: an escaped backslash does not escape the
character after it <a href="https://github.com/ljharb/shell-quote/commit
/d708019016ce26e1a8a05af4b296e35ef8095c9e"><code>d708019</code></a></li>
<li>[Fix] <code>quote</code>: preserve <code>!</code> in arguments that
also contain <code>'</code> <a href="https://github.com/ljharb/shell-quo
te/commit/ad399279dbbbd086967d2040c1558b4888b074e6"><code>ad39927</code>
</a></li> <li>[Fix] <code>parse</code>: treat <code>$_name</code> as a
variable name, not <code>$_</code> followed by text <a
href="https://github.com/ljharb/shell-quote/commit/28f88cd422ae4046aca95
56c4b74ca90b0ea7f6b"><code>28f88cd</code></a></li> <li>[Fix]
<code>quote</code>: preserve empty glob patterns <a
href="https://github.com/ljharb/shell-quote/commit/35c9b97a744211091b772
f145bef0b6a5562b68e"><code>35c9b97</code></a></li> <li>[Fix]
<code>quote</code>: escape <code>~</code> in glob patterns to prevent
shell tilde-expansion <a href="https://github.com/ljharb/shell-quote/com
mit/239d49cae6d231436ea4e676850037018c790c49"><code>239d49c</code></a></
li> <li>[Dev Deps] update <code>@ljharb/eslint-config</code>,
<code>auto-changelog</code>, <code>eslint</code>, <code>evalmd</code> <a
href="https://github.com/ljharb/shell-quote/commit/b1e406ed4287a134cc649
db47b9a59e21b304472"><code>b1e406e</code></a></li> <li>[meta] npmignore
some files <a href="https://github.com/ljharb/shell-quote/commit/ebfc308
0cf5f68db5edfddfba49dc8c4ccacd2d5"><code>ebfc308</code></a></li>
<li>[actions] add permissions <a href="https://github.com/ljharb/shell-q
uote/commit/3429b0d349211786765e9e68478e029d96ad44e9"><code>3429b0d</cod
e></a></li> <li>[actions] set least-privilege <code>cache-mode</code> <a
href="https://github.com/ljharb/shell-quote/commit/36f23944db50dd3f0df4d
a9c7cba0bb63df05f64"><code>36f2394</code></a></li> <li>[Dev Deps] update
<code>eslint</code> <a href="https://github.com/ljharb/shell-quote/commi
t/6de9a41ecfc4fe9f9546df08866c8ead039f8909"><code>6de9a41</code></a></li
> </ul> </blockquote> </details> <details> <summary>Commits</summary>
<ul> <li><a href="https://github.com/ljharb/shell-quote/commit/6ecb8aa61
8ba6dc6c3b087fce6d7660320d2adeb"><code>6ecb8aa</code></a> v1.12.0</li>
<li><a href="https://github.com/ljharb/shell-quote/commit/3a7b4ae3960c3f
f4413932e276c5b0ecb3a2b456"><code>3a7b4ae</code></a> [Dev Deps] update
<code>@ljharb/eslint-config</code></li> <li><a
href="https://github.com/ljharb/shell-quote/commit/7d688b9bec1917a22cccd
4d4c887128a9c66e8a0"><code>7d688b9</code></a> [New] <code>parse</code>:
support the <code>case</code> test-next terminator
(<code>;;&amp;</code>)</li> <li><a
href="https://github.com/ljharb/shell-quote/commit/f27010ed04bcd925795b3
50afb1c49e36bbd1ba3"><code>f27010e</code></a> [New] <code>parse</code>:
support the <code>case</code> fall-through terminator
(<code>;&amp;</code>)</li> <li><a href="https://github.com/ljharb/shell-
quote/commit/90cde9cfd8af30fcb65e9fd2cb2f9e181d3f103b"><code>90cde9c</co
de></a> [New] <code>parse</code>: support appending stdout and stderr
(<code>&amp;&gt;&gt;</code>)</li> <li><a
href="https://github.com/ljharb/shell-quote/commit/6ad6cd215f89adcc29dd6
01e085fa54083c2f911"><code>6ad6cd2</code></a> [New] <code>parse</code>:
support redirecting stdout and stderr (<code>&amp;&gt;</code>)</li>
<li><a href="https://github.com/ljharb/shell-quote/commit/20533154bb5780
9c80f55318b8493aef49505f4e"><code>2053315</code></a> [New]
<code>parse</code>: support output process substitution
(<code>&gt;(</code>)</li> <li><a href="https://github.com/ljharb/shell-q
uote/commit/b78d19c14da6356cc12c46b3478203247ab8a295"><code>b78d19c</cod
e></a> [New] <code>parse</code>: support redirecting output despite
<code>noclobber</code> (<code>&gt;|</code>)</li> <li><a
href="https://github.com/ljharb/shell-quote/commit/21cc333eb0ce5bf094f59
5b7fdc01b3447ffd4b0"><code>21cc333</code></a> [New] <code>parse</code>:
support opening a file for reading and writing
(<code>\&lt;&gt;</code>)</li> <li><a
href="https://github.com/ljharb/shell-quote/commit/dbfac376d4065d37539d3
abdb5e76847f93797d3"><code>dbfac37</code></a> [New] <code>parse</code>:
support tab-stripping here-documents (<code>&lt;&lt;-</code>)</li>
<li>Additional commits viewable in <a
href="https://github.com/ljharb/shell-
quote/compare/v1.10.0...v1.12.0">compare view</a></li> </ul> </details>
<br />

[![Dependabot compatibility score](https://dependabot-
badges.githubapp.com/badges/compatibility_score?dependency-name=shell-
quote&package-manager=npm_and_yarn&previous-version=1.10.0&new-
version=1.12.0)](https://docs.github.com/en/github/managing-security-
vulnerabilities/about-dependabot-security-updates#about-compatibility-
scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end)

---

<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/tursodatabase/turso/network/alerts).

</details>

Closes #9872
2026-10-15 11:25:04 +03:00
Pekka Enberg
9cb866b8cf Merge 'core/translate: open a statement savepoint for UPDATEs that change the rowid' from Nikita Sivukhin
## Problem

Inside an explicit transaction, an UPDATE that changes several rows and
then fails could keep the rows it had already changed, and `COMMIT`
would save them:

```sql
CREATE TABLE t(k INTEGER PRIMARY KEY, v);
INSERT INTO t VALUES (1,1),(2,2),(5,5),(15,15);
BEGIN;
UPDATE t SET k = k + 10 WHERE k BETWEEN 1 AND 5;  -- UNIQUE constraint failed (5 -> 15)
COMMIT;
SELECT k FROM t;  -- SQLite: 1,2,5,15   Turso: 5,11,12,15
```

`set_update_stmt_journal_flags` decides whether to open a statement
savepoint by checking whether the UPDATE can fail with ABORT. It missed
two cases:

- **Changing the rowid or INTEGER PRIMARY KEY.** The rowid is unique,
and assigning a non-integer to it fails with "datatype mismatch". But
the check only counted UNIQUE indexes and `unique_sets`.
- **NOT NULL generated columns computed from a SET column.** Only the
SET columns themselves were checked for NOT NULL.

## Fix

The check now looks at every column the UPDATE affects
(`columns_affected_by_update`), and counts a rowid change as a possible
UNIQUE failure. `OR IGNORE`, `OR REPLACE` and `OR FAIL` keep their
current behavior, which matches SQLite: SQLite also keeps partial
changes there.

## Tests

New tests in `tests/integration/stmt_journal.rs`, run in both WAL and
MVCC modes where possible: INTEGER PRIMARY KEY conflict, plain rowid
conflict, datatype mismatch, NOT NULL generated column, and a check that
the savepoint flag is set. Without the fix 8 test runs fail; with it,
all pass. The full integration suite and the sqltest conformance runner
pass.

## Not fixed here

A runtime error in a read-only statement inside `BEGIN` (for example
`sum()` overflow in a SELECT) rolls back the whole transaction, while
SQLite only fails that statement. This comes from the `TxnCleanup::None`
branch in `Program::abort`. It is left for a separate change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-by: Mikaël Francoeur (@LeMikaelF)

Closes #9642
2026-10-15 11:21:39 +03:00
Jussi Saurio
63d2c4ca3e Merge 'core/datetime: stop date and time arguments at the first NUL' from app/turso-github-handyman
SQLite's date and time functions read their arguments as C strings, so
text, or a blob read as text, ends at the first NUL. Turso parsed the
whole value. A time value or modifier with a NUL and more bytes after it
returned NULL, and a `strftime` format kept the bytes after the NUL.

```sql
SELECT date('2024-01-01' || char(0) || 'x');               -- Turso: NULL, SQLite: 2024-01-01
SELECT time(x'3700');                                     -- Turso: NULL, SQLite: 12:00:00
SELECT date('2024-01-01', '+1 day' || char(0) || 'x');    -- Turso: NULL, SQLite: 2024-01-02
SELECT hex(strftime('%Y' || char(0) || '%m', '2024-05-01')); -- Turso: 32303234003035, SQLite: 32303234
```

All date function arguments already go through one helper that turns a
blob into text. That helper, now named `arg_as_text`, cuts text and
blobs at the first NUL with `sqlite_text_prefix` and `first_nul`, the
functions LIKE, GLOB, `substr()` and `length()` already use. The
`strftime` format now goes through the same helper. A blob is cut before
the UTF-8 check, so `time(x'3700ff')` gives `12:00:00` like SQLite.

Fixes #9935

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9936
2026-10-15 11:13:59 +03:00
Jussi Saurio
58d867c9d1 Merge 'core/json: read BLOB path arguments as text' from app/turso-github-handyman
JSON functions failed when the path argument was a BLOB, while SQLite
reads the BLOB's bytes as the path text:

```
SELECT json_set('[1]', x'245b305d', 5);
-- SQLite: [5]
-- Turso:  Runtime error: JSON path error near: "$[0]"
```

The same happened in `json_insert`, `json_replace`, `json_remove`,
`json_extract`, `json_type`, `->` and `->>`. `json_each` and `json_tree`
failed with `root path should be text`.

`json_path_from_db_value` accepted only a TEXT path (and, for
`->`/`->>`, a number). Every other type went to the path error. The
`json_each`/`json_tree` cursor also required `Value::Text`.

The new `json_path_text` helper returns the text of a TEXT or BLOB path.
A BLOB that is not valid UTF-8 has its bad bytes replaced, as in
`CAST(blob AS TEXT)`. `json_path_from_db_value`, the non-JSONB BLOB
value check in `json_set`/`json_insert`/`json_replace`, and the
`json_each`/`json_tree` root path all use it. As a result, `json_tree`'s
check for unsupported negative indices now also covers BLOB paths. An
invalid BLOB path, such as `json_extract('{"a":1}', x'2461')`, still
fails with `bad JSON path`.

Fixes #9941

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9942
2026-10-15 11:12:26 +03:00
Jussi Saurio
6998e0337c Merge 'core/translate: finish the deferred seek before UPDATE writes a row through an index' from app/turso-github-handyman
An UPDATE that scans a covering index could write the row while the
table cursor was still on the wrong row. This happened when a partial
index on an updated column has a WHERE that reads only the rowid. If the
table cursor was not positioned yet, Turso panicked in
`insert_into_page` (`self.current_page >= 0`). If it was still on an
earlier row, the row was written there, which left a duplicate rowid:

```sql
CREATE TABLE t(id INTEGER PRIMARY KEY, a, b);
CREATE INDEX ia ON t(a);
CREATE INDEX ib ON t(b) WHERE id > 1;
INSERT INTO t VALUES (2, 1, 0), (1, 2, 0);
UPDATE t SET b = 9 WHERE a > 0;
SELECT * FROM t;
PRAGMA integrity_check;
```

Turso printed `1|2|0`, `1|2|9`, `2|1|9` and `wrong # of entries in index
ia`. SQLite prints `1|2|9`, `2|1|9`, `ok`.

The UPDATE emitter left out `FinishSeek` before the table `Insert` if
any `Column` read on the table cursor appeared in the loop body. Here
the only such read is the old value for the partial index's `IdxDelete`,
and it runs only for rows that match the partial index's WHERE. For
other rows the deferred seek never ran before `Insert`.

As in SQLite's `update.c`, `FinishSeek` is now left out only when the
new record loads an unchanged column from the table cursor, a read that
runs for every row. The `update-returning-star` snapshot gains a
`FinishSeek`. In that query Turso reads the unchanged column from the
index, where SQLite reads it from the table, so the new record does no
table load. The `FinishSeek` does nothing at runtime there.

Fixes #9932

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9943
2026-10-15 11:11:00 +03:00
Turso Agent
9d6358a2ce core/translate: finish the deferred seek before UPDATE writes a row through an index
Fixes #9932
2026-10-15 07:20:47 +00:00
Turso Agent
67e15efb65 core/json: read BLOB path arguments as text
Fixes #9941
2026-10-15 07:16:03 +00:00
Jussi Saurio
f4a7e23a8b Merge 'core/json: reject non-JSONB blob values in json_insert and json_replace' from app/turso-github-handyman
`json_insert`, `json_replace` and their `jsonb_*` versions, plus
`jsonb_set`, accepted a BLOB value that is not JSONB. SQLite rejects it.
Only `json_set` called `ensure_blob_arg_is_jsonb` on its values.

```sql
SELECT json_insert('[]','$[#]',x'7b7d');
-- before: []
-- after:  error: JSON cannot hold BLOB values (same as SQLite)
```

All six functions now get their path through one helper, which checks
the value in SQLite's order. A NULL path skips the pair without looking
at the value. A path that does not start with `$` is reported as a bad
path first. Otherwise the blob is rejected before the rest of the path
is parsed. This also fixes `json_set`, which used to check the blob
before the path: `json_set('[1]', NULL, x'7b7d')` now returns `[1]` and
`json_set('[1]', 'bad', x'7b7d')` now reports the bad path, both
matching SQLite. Valid JSONB blobs such as `json_insert('{}', '$.a',
x'01')` still work.

Fixes #9937

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9938
2026-10-15 09:52:55 +03:00
Turso Agent
5035e4428f core/datetime: stop date and time arguments at the first NUL
Autofixer-Repair: review
2026-10-15 06:46:54 +00:00
Jussi Saurio
1eea365010 Merge 'core/translate: skip partial index WHERE terms in hash join build subplans' from app/turso-github-handyman
A query that reads a partial index on the build side of a hash join
could panic with "column N of table tN is not stored in the index and
the table cursor is not open".

```sql
CREATE TABLE t(a, b);
CREATE TABLE u(x);
CREATE INDEX i ON t(a) WHERE b > 1;
INSERT INTO t VALUES (2, 3);
INSERT INTO u VALUES (2);
SELECT count(*) FROM t JOIN u ON u.x = t.a WHERE a = 2 AND b > 1;
-- before: panic
-- after:  1 (same as SQLite)
```

The plan that fills the hash join's build table copies the WHERE terms
and clears every term's consumed flag, because some access methods are
replaced by scans in that plan. The seek on the partial index `i` is
kept, though, and the coverage check still treats `b` as covered because
`b > 1` matches the index's WHERE clause, so no table cursor is opened.
Emitting `b > 1` then reads a column that neither the index nor an open
cursor provides.

After the access methods are checked, the build-side plan now marks the
WHERE terms implied by each partial index it still reads as consumed.
This calls the same `mark_partial_index_predicate_terms_consumed` the
optimizer uses for the main plan. A table that falls back to a plain
scan keeps the term as a normal filter.

Fixes #9934

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9940
2026-10-15 09:40:03 +03:00
Pekka Enberg
58f8e36914 Merge 'postgres: disable load_extension on the wire listener' from Sebastien Tardif
`tursopg --server` no longer enables SQL `load_extension`. Interactive
CLI and one-shot SQL still do.

The wire listener is `NoopHandler` (no password). It used to open the
database with `DatabaseOpts::turso_cli()`, which sets
`enable_load_extension = true`. `SELECT
load_extension('/path/to/module')` is valid PostgreSQL-looking SQL,
resolves to the SQLite builtin, and would `dlopen` that path.

The library default is off.
[#3250](https://github.com/tursodatabase/turso/pull/3250) turned SQL
extension loading off for that reason.
[#8658](https://github.com/tursodatabase/turso/pull/8658) already draws
the same wire-vs-CLI line for filesystem `COPY FROM`.

SQLite's `sqlite3_enable_load_extension` is off unless the host turns it
on. A network listener that copies CLI opts inherits a local-REPL
privilege.

Without this change, any client that can reach `--server` (the help text
suggests `0.0.0.0:5432`) can load a shared library into the server
process.

CLI still returns `Extension file not found` for a missing path. The
listener now returns `runtime extension loading is disabled` and never
opens the file.

Tests:
- `wire_load_extension_is_disabled`
- `repl_load_extension_still_attempts_to_open_the_file`

Related: [#3250](https://github.com/tursodatabase/turso/pull/3250),
[#8658](https://github.com/tursodatabase/turso/pull/8658)

Assisted with implementation and tests. I reviewed the change and the
test results.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #9035
2026-10-15 09:12:40 +03:00
Turso Agent
568a017bfe core/translate: skip partial index WHERE terms in hash join build subplans
Fixes #9934
2026-10-15 05:29:21 +00:00
Nikita Sivukhin
6c584362f5 core/translate: open a statement savepoint for UPDATEs that change the rowid
Inside BEGIN, an UPDATE that changes many rows and fails partway through
must undo the rows it already changed. Turso decides whether to open a
statement savepoint by checking if the UPDATE can fail with ABORT. That
check missed two cases, so the earlier rows stayed changed and were
written by COMMIT:

- Changing the rowid or INTEGER PRIMARY KEY. The rowid is unique, and
  assigning a non-integer to it fails with "datatype mismatch", but only
  UNIQUE indexes and unique_sets were counted. For example
  UPDATE t SET k = k + 10 WHERE k BETWEEN 1 AND 5 kept rows 1 and 2
  changed after failing on row 5.
- NOT NULL generated columns computed from a SET column. Only the SET
  columns themselves were checked for NOT NULL.

The check now looks at every column the UPDATE affects. OR IGNORE,
OR REPLACE and OR FAIL keep their current behavior, which matches SQLite.

Tests: tests/integration/stmt_journal.rs (WAL and MVCC); the new tests
fail without the fix and pass with it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 08:16:55 +03:00
Sebastien Tardif
f3309d06f4 postgres: disable load_extension on the wire listener
tursopg --server reused DatabaseOpts::turso_cli(), which turns on SQL
load_extension. The listener has no password (NoopHandler). A client
could SELECT load_extension and run native code in the server process.

Interactive CLI still enables the flag. The wire path uses the library
default (off), matching sqlite3_enable_load_extension and #3250.

Tests: tursopg wire_load_extension_is_disabled,
       repl_load_extension_still_attempts_to_open_the_file
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
2026-10-15 08:16:48 +03:00
Pekka Enberg
807e7a2a9a tests/integration: pass ConnectOpts in header_version connect calls
Database::connect now takes a ConnectOpts argument, but the
header_version tests merged after that change still call it with no
arguments, so the integration_tests binary does not compile on main.

Tests: cargo test -p core_tester --test integration_tests header_version
2026-10-15 08:16:06 +03:00
Turso Agent
ebecb37f16 core/json: reject non-JSONB blob values in json_insert and json_replace
Fixes #9937
2026-10-15 05:13:58 +00:00
Pekka Enberg
dd7577496e Merge 'simulator: correct MVCC rowid assumptions and validation' from Glauber Costa
Under MVCC, implicit rowid allocation behaves like a sequence: the next
value comes from a high-water mark that a rollback does not lower, so an
aborted insert consumes its rowid for good and the next insert skips
past it. This is deliberate — we do not guarantee that a rolled-back
allocation is handed back, matching PostgreSQL sequences, where
`nextval` is never rolled back and aborted transactions leave permanent
gaps. (AUTOINCREMENT already behaved this way; the same rule now covers
plain `INTEGER PRIMARY KEY` rowids.) WAL mode, like SQLite, reuses the
freed value.

The differential simulator makes exact-row assertions, and it cannot
predict a post-rollback rowid without modeling that watermark. Rather
than model it, this generates explicit integer primary keys in MVCC
INSERT and UPSERT workloads, so the assertions no longer assume rolled-
back allocations come back. WAL mode keeps generating implicit keys.

It also splits validation by mode: MVCC integrity is checked with Turso
(which can read the logical-log state SQLite cannot) while WAL keeps the
SQLite check, and the in-memory I/O now exports the logical log so a
retained failure artifact includes committed state.

Tests: 21 generator tests, the MVCC profile regression, and
deterministic integrity and export regressions pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #9806
2026-10-15 08:02:26 +03:00
Pekka Enberg
e2386daabd Merge 'core/translate: validate CHECK constraints in ALTER COLUMN' from app/turso-github-handyman
`ALTER TABLE ... ALTER COLUMN` stored the new column definition without
checking its CHECK constraints, so a CHECK that names a column the table
doesn't have was saved to the schema. Every later INSERT then failed:

```sql
CREATE TABLE t(id INTEGER PRIMARY KEY, v INTEGER);
ALTER TABLE t ALTER COLUMN v TO v2 INTEGER CHECK(nosuch > 0); -- succeeded
INSERT INTO t VALUES (1, 1); -- Parse error: no such column: nosuch
```

`ADD COLUMN` already rejects this through `validate_check_expr`. ALTER
COLUMN now runs the same check on each CHECK in the new definition,
against the table's column names after the rename. The ALTER above now
fails with `no such column: nosuch` and the schema is left unchanged. A
CHECK that uses the column's old name is rejected the same way, while
`CHECK(v2 > 0)` is still accepted and enforced.

Fixes #9893

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9908
2026-10-15 07:57:35 +03:00
Pekka Enberg
ac9dd57eb3 Merge 'core/translate: rewrite WHERE BETWEEN before binding columns' from app/turso-github-handyman
`parse_where` bound each WHERE term and only then split `x BETWEEN lo
AND hi` into `x >= lo AND x <= hi`. Binding counts each column
reference, so the columns in `x` were counted once even though they
appear in two comparisons. When one comparison matched a partial index's
WHERE, the coverage check decided that was the only use of the column.
It dropped the column from the needed columns and picked a covering
index scan with no table cursor. The other comparison then panicked
trying to read the column.

```sql
CREATE TABLE t(a INT, b);
CREATE INDEX i ON t(b) WHERE a >= 2;
INSERT INTO t VALUES (3, 'x'), (1, 'y');
SELECT count(*) FROM t WHERE a BETWEEN 2 AND 4;
```

Before: panic `column 0 of table t1 is not stored in the index and the
table cursor is not open`. After: `1`, same as SQLite.

The fix splits BETWEEN before binding, so every column reference in both
comparisons is counted.

Fixes #9926

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9931
2026-10-15 07:56:21 +03:00
Pekka Enberg
839061c730 Merge 'core: read the current time for date functions from the IO clock' from app/turso-github-handyman
Date functions that use the current time (`date('now')`, `datetime()`,
`strftime('%s')`, `unixepoch('now')`, `julianday('now')`,
`timediff('now', ...)`, date `+`/`-`) called `SystemTime::now()`
directly, so a custom IO's clock had no effect on them. The IO layer
already has `Clock::current_time_wall_clock()` for this. The datetime
functions now take a `&dyn Clock`, and the VDBE passes `pager.io`.

`CURRENT_DATE`, `CURRENT_TIME` and `CURRENT_TIMESTAMP` had the same
problem, and were also computed once when the statement was compiled, so
a prepared statement kept returning the time it was prepared at. They
now compile to runtime calls to `date()`, `time()` and `datetime()`,
like SQLite, so they read the IO clock each time the statement runs.

With an IO whose wall clock returns 1000000000 seconds:

```sql
SELECT datetime('now'), CURRENT_DATE;
-- before: 2026-10-12 13:31:55|2026-10-12
-- after:  2001-09-09 01:46:40|2001-09-09
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Fixes #9793

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9797
2026-10-15 07:49:15 +03:00
Pekka Enberg
26c9a11acc Merge 'core/mvcc: stop AUTOINCREMENT from overwriting rows after a switch to MVCC' from Jussi Saurio
## Problem

After a database switches to MVCC, every AUTOINCREMENT insert overwrites
an existing row.

```sql
CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT);
INSERT INTO posts (title) VALUES ('a'), ('b'), ('c'), ('d');
PRAGMA journal_mode = 'mvcc';
INSERT INTO posts (title) VALUES ('e');
INSERT INTO posts (title) VALUES ('f');
INSERT INTO posts (title) VALUES ('g');
SELECT id, title FROM posts;
-- before: 1|e  2|f  3|g  4|d                    (a, b and c are gone)
-- after:  1|a  2|b  3|c  4|d  5|e  6|f  7|g
```

## Why this is serious

- **Data loss.** Each new row replaces an old row with the same id. The
old row is gone.
- **No error.** The inserts succeed. Nothing tells the user that rows
were lost.
- **Every such database.** It is not a race or an edge case. Any
database with an AUTOINCREMENT table loses rows on its first inserts
after the switch.
- **It keeps going.** Ids restart at 1, so each insert replaces the next
old row, until the ids pass the old largest id.
- **It breaks the one promise AUTOINCREMENT makes.** AUTOINCREMENT
exists so that an id is never handed out twice.

Switching an existing database to MVCC is how users adopt MVCC, so this
hits exactly the users who try it.

## Why

In WAL mode, AUTOINCREMENT keeps its counter in `sqlite_sequence`. In
MVCC mode, it keeps the counter in a separate sequence table.

When a database switches to MVCC, startup copies each `sqlite_sequence`
value into the sequence table. In the example, that means: move `posts`
from "next id is 1" to "last id was 4".

That copy was never committed:

- The copy runs as internal helper statements.
- Helper statements never commit on their own. They expect a parent
statement to commit for them.
- At startup there is no parent statement.

So the copy was thrown away, and the sequence handed out 1, 2, 3, ...
again.

## Fix

1. The copy now ends by committing its own transaction. It uses the same
commit (`commit_tx`) that a statement uses, and shares the cleanup after
it (`end_committed_main_mvcc_tx`).
2. The copy skips sequences that are already up to date. Every open of
the database runs it, and a write on each open would grow the MVCC log
and make a read-only open fail.

### Why commit directly, instead of running ordinary statements

Ordinary statements commit on their own. Bootstrap already uses them to
create the MVCC metadata table. The copy cannot:

- Ordinary statements may not write the internal sequence tables ("table
... may not be modified").
- The bootstrap connection is exempt from that rule, but the same flag
also turns off reads from the MVCC store. The copy must read sequence
rows that log recovery just put in the MVCC store, so it runs after that
flag is cleared.

The one existing helper that commits outside a statement
(`commit_main_mvcc_tx_for_wal_session`) blocks on I/O and exists only
with the `conn_raw_api` feature. The copy runs in a state machine that
must not block.

Still open: a file created by sqlite3 has no sequence table, so every
insert after the switch fails with "missing backing table for sequence".
That fails with an error; no rows are lost.

## Tests

- `test_autoincrement_continues_after_switch_to_mvcc_and_reopen`: insert
right after the switch, reopen twice without writes, open read-only,
insert again. Fails without the fix.
-
`test_autoincrement_watermark_is_committed_when_opening_mvcc_database`:
marks a WAL file as MVCC, then opens it and inserts. Fails without the
fix.

## Depends on

Stacked on #9678, which refuses `PRAGMA journal_mode` inside a
transaction. With this PR alone, a switch inside a transaction still
runs, and after the user's COMMIT or ROLLBACK the database cannot be
opened again. #9678 makes sure the switch never runs there.

Part of #9504

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #9668
2026-10-15 07:43:47 +03:00
Pekka Enberg
a3434d47fd Merge 'sqltest: add a postgres backend' from Mikaël Francoeur
This PR adds a `postgres` backend to the sqltest runner.

Reviewed-by: Pedro Muniz (@pedrocarlo)

Closes #9922
2026-10-15 07:36:23 +03:00
Pekka Enberg
6e3dc53102 Merge 'core/json: stop rewriting 9.0e+999 in json() output and write 9e999 for json_set values' from app/turso-github-handyman
`json()` ran a text replace of `9.0e+999` with `9e999` over the whole
serialized document. That changed string contents and number text taken
from the input. Separately, the REAL-to-JSONB conversion always wrote an
infinite REAL as `9.0e+999`, so `json_set`/`json_insert`/`json_replace`
disagreed with SQLite.

```sql
SELECT json('{"note":"x 9.0e+999 y"}');   -- was {"note":"x 9e999 y"}, now {"note":"x 9.0e+999 y"}
SELECT json('[9.0e+999]');                  -- was [9e999], now [9.0e+999]
SELECT json_set('[1]', '$[0]', 9e999);      -- was [9.0e+999], now [9e999]
```

SQLite writes `9e999` when it converts a SQL value passed as a JSON
argument: `json()`, `jsonb()`, and the values given to
`json_set`/`json_insert`/`json_replace`. Only `json_array`,
`json_object`, `json_quote` and the group aggregates print `9.0e+999`.
The conversion now follows that rule:

- An infinite REAL becomes `9e999` unless the mode is `Conv::NotStrict`,
which the array/object builders use.
- `json_quote` uses `NotStrict`.
- A new `Conv::SetValue` mode is used for the values of the
set/insert/replace functions. It treats text like `NotStrict` but writes
`9e999`.

The text replace in `get_json` is removed. As a side effect, `9e999 ->
'$'` now returns `9e999`, as in SQLite.

Fixes #9927

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9930
2026-10-15 07:34:47 +03:00
Claude
c4ff6b5fdd postgres/conformance: run the pg-sqltests on PostgreSQL in CI
`make -C postgres/conformance run-postgres` runs the corpus with the
postgres backend. It uses the server at PG_DSN. If PG_DSN is not set,
with-postgres.sh starts a throwaway PostgreSQL container with Docker and
gives it a role that has CREATEDB and is not a superuser. A new CI job,
"Run SQL tests (PostgreSQL)", runs the target.

The container keeps its data on tmpfs and runs with fsync,
synchronous_commit, full_page_writes, autovacuum and JIT off, and with
wal_level=minimal. These settings do not change query results. The
target runs two tests per CPU, because a test often waits for the
server. With the LATERAL tests of #9468, 848 tests take about 6 s on 4
CPUs, against about 60 s with the default settings.

The PostgreSQL version is one line in with-postgres.sh, and
POSTGRES_VERSION changes it for one run. The image comes from
mirror.gcr.io, because Docker Hub limits the pull rate of anonymous
clients.

40 of the 187 tests failed on PostgreSQL 17. They check Turso-specific
behavior: the EXPLAIN output, the catalogs that Turso keeps empty, and
the error for a write to a catalog table. Three of them fail because
Turso has the ACLs of PostgreSQL 16, without the MAINTAIN privilege of
PostgreSQL 17. Mark them with @skip-if postgres, with a reason that
tells what PostgreSQL does.

Tests: make -C postgres/conformance run-postgres, which failed 40 tests
before the skips; make -C postgres/conformance run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R3hzXhfjBgyLPUF7vd3PHW
2026-10-15 03:04:08 +00:00
Claude
6bcb8e6def sqltest: add a postgres backend that runs tests on a real PostgreSQL server
The PostgreSQL corpus must expect only what PostgreSQL itself does, but
until now it ran only against tursopg. An expectation that only tursopg
meets passed CI, and nothing showed that it was wrong.

`--backend postgres --postgres-dsn <url>` runs the tests on the server at
the URL. For each test, the backend creates a new database from
template0 and drops it after the test, so tests stay isolated when they
run in parallel. At most four CREATE DATABASE and DROP DATABASE
statements run at the same time, so a run uses at most --jobs + 4
connections. A random part in the database names lets two runs share
one server.

`@skip-if postgres "reason"` and `@skip-file-if postgres "reason"` skip
tests of Turso-specific behavior on this backend. `postgres` is parsed
from an identifier, not a keyword token, so `@backend postgres` and
names such as `setup postgres` still parse.

Tests: parser and runner unit tests for the skip condition, and the
pg-sqltests corpus against PostgreSQL 17

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R3hzXhfjBgyLPUF7vd3PHW
2026-10-15 03:04:08 +00:00
Claude
6d81521581 sqltest: move the wire-protocol connection out of the tursopg backend
The next change adds a postgres backend, which sends queries to a real
PostgreSQL server in the same way that the tursopg backend sends them to
tursopg. Move the connection setup and the simple query handling into
PgConnection, so that both backends use the same code.

No change in behavior.

Tests: make -C postgres/conformance run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R3hzXhfjBgyLPUF7vd3PHW
2026-10-15 03:04:08 +00:00
Claude
a6cc01b42c sqltest: rename the pg backend to tursopg
The pg backend runs the PostgreSQL corpus against tursopg. The next
change adds a backend that runs the same corpus against a real
PostgreSQL server, and "pg" can mean either server. Name the backend
after the server that it starts.

`--backend pg` becomes `--backend tursopg`, and `@backend pg` and
`expect @pg` become `@backend tursopg` and `expect @tursopg`. No corpus
file used the old name. The CI job is now "Run SQL tests (tursopg
backend)".

Tests: test_parse_tursopg_backend, make -C postgres/conformance run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R3hzXhfjBgyLPUF7vd3PHW
2026-10-15 03:04:07 +00:00
Turso Agent
86b39df1bd core/translate: rewrite WHERE BETWEEN before binding columns
Fixes #9926
2026-10-15 03:01:37 +00:00
Turso Agent
1ce8fc0631 core/json: stop rewriting 9.0e+999 in json() output and write 9e999 for json_set values
Fixes #9927
2026-10-15 02:48:42 +00:00
Turso Agent
63e70e10e3 core/translate: validate CHECK constraints in ALTER COLUMN
Fixes #9893
2026-10-15 02:31:38 +00:00
Jussi Saurio
a6613696e4 Merge 'postgres: map schema names in schema.table.column references' from app/turso-github-handyman
Three-part column references failed for the `pg_catalog`, `public` and
`information_schema` schemas:

```
SELECT pg_catalog.pg_namespace.nspname FROM pg_catalog.pg_namespace LIMIT 1;
Error: Parse error: no such column: pg_catalog.pg_namespace.nspname
```

PostgreSQL returns a row. The translator maps these schemas to `main`
when the table appears in `FROM`, but passed the schema of a
`schema.table.column` reference through unchanged, so it never matched
the table. User-created schemas (`s.t.a`) already worked.

The schema mapping now lives in `map_schema_name`, which both the `FROM`
code and the column reference code use. The table name in the column
reference stays as written, because `FROM` aliases renamed tables (such
as `information_schema.schemata`) with their original name, so
`information_schema.schemata.schema_name` also resolves.

Fixes #9890

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9891
2026-10-15 05:30:32 +03:00
Jussi Saurio
e85d4a3091 Merge 'core/translate: validate existing rows against new constraints in ALTER COLUMN' from app/turso-github-handyman
`ALTER TABLE ... ALTER COLUMN` only checked existing rows against the
new column's NOT NULL and CHECK constraints when it also rewrote the
rows (a change to type affinity, STRICT type, or generated/virtual
status). Adding a constraint without changing the type skipped that
check, so the ALTER succeeded over rows that break the new constraint
and `PRAGMA integrity_check` then failed.

```sql
CREATE TABLE t(id INTEGER PRIMARY KEY, v INTEGER);
INSERT INTO t VALUES(1,-1);
ALTER TABLE t ALTER COLUMN v TO v2 INTEGER CHECK(v2>0);
PRAGMA integrity_check;
```

Before: the ALTER succeeds and integrity_check reports `CHECK constraint
failed in t`. After: the ALTER fails with `CHECK constraint failed:
v2>0` and the schema is left unchanged. The same applies to adding `NOT
NULL` over a NULL value.

The row check now runs for every ALTER COLUMN, before any row rewrite.
It returns right away when the new definition has no NOT NULL or CHECK.
The function is renamed from `emit_add_virtual_column_validation` to
`emit_column_constraints_validation` because it is no longer only used
for virtual columns.

Fixes #9892

Autofixer wrote this change with Claude Code in an isolated sandbox. A
separate verifier agent tested and reviewed it in its own container
before this PR was opened. A maintainer must review it before merge.

To have Autofixer address review feedback, leave your comments and then
mention @turso-github-handyman; it handles all unanswered comments from
maintainers in one round.

Closes #9912
2026-10-15 05:12:10 +03:00
Pere Diaz Bou
d808271a35 Merge 'core/mvcc: collect checkpoint rows from dirty keys instead of every row' from Pere Diaz Bou
## Problem statement

A Passive checkpoint walked every live key in the version store on each
run. While readers or writers hold snapshots, GC keeps the old rows, so
the walk grew with the table instead of with the rows committed since
the last checkpoint. With a helper connection checkpointing every second
at 4 writers, the checkpoint time climbed for the whole run.

## Changes

Commits record their write set keys in two lock-free SkipMaps on the
store, one for table rows and one for index rows. Each entry holds the
end timestamp of the last commit that marked the key. The mark runs in a
new chunked `MarkDirtyKeys` state after the log record is built and
before the log append, so an allocation failure still fails the commit.

Collect walks the dirty maps, schema keys first, and reads each chain
from the store at visit time. A pinned cursor steps through the row
store to the next dirty key and seeks only when the key is far, so a
dense run of inserts costs a sequential walk. A key whose stamp is at or
below the snapshot becomes a prune candidate. A new `PruneDirtyKeys`
state after publish removes the candidates. If a commit marked the key
after the visit, the stamp rose and the key stays. A failed checkpoint
never reaches prune, so it keeps every key.

A new or recovered store scans every row once and then clears the full-
scan request. Passive sequence compaction marks the rows it stamps.
Debug builds run a full scan after each dirty collect and assert that
every checkpointable row is a dirty key.

## Checkpoint starvation

The test in #9220 shows that a forward collect walk never finishes while
a writer appends rows. Each yield let the writer add as many keys ahead
of the cursor as the walk visited. The schema-first forward walk from
#9120 has this problem, and the dirty-key walk in this PR had it too.

The walk now covers one table at a time. When it enters a table, it
reads the last key that the table has at that moment and does not visit
keys above it. Rows committed after the snapshot that land above that
key are not checkpointable in this run, so nothing is lost. The bound
applies to the dirty table map, the dirty index map, the row store on a
full scan, the stamp pass after a full scan, and each index in the index
full scan. The test from #9220 passes on this branch, and two unit tests
append a full batch of rows after every yield and fail without the
bound.

`BeforeCollectTableRows` sits at the end of `CheckpointYieldPoint`.
Simulator plans store yield points as ordinals, so the earlier placement
in the middle of the enum changed which hook old seeds fire on.

## Results

perf/latency, Turso only, 4 connections, 10-row inserts, tmpfs, one
checkpoint per second from a helper connection. Base is the head of
#9120. One extra connection held a read snapshot open for the run so GC
kept history.

| Run | Base checkpoint p50 | This PR checkpoint p50 | Base worst | This
PR worst |
|---|---|---|---|---|
| Held snapshot, 5000 tx/s, 30 s | 151 ms | 100 ms | 582 ms | 188 ms |
| No held snapshot, 5000 tx/s, 30 s | 84 ms | 84 ms | 148 ms | 142 ms |
| Held snapshot, 30000 tx/s, 20 s | 1014 ms | 1116 ms | 3306 ms | 3458
ms |

Transaction latency did not move: p50 0.04 ms and p99 0.20 ms in both
builds at 5000 tx/s. With the held snapshot, p99.9 fell from 0.86 ms to
0.53 ms. Writers used about 2 percent more of one core for the extra map
insert at commit. At 30000 tx/s both builds fall behind the writers and
the difference is inside run-to-run noise.

The isolated benchmark `checkpoint_n_rows` gains a second measurement: a
reader holds a snapshot, N rows are checkpointed while the snapshot
keeps their versions in the store, 10,000 more rows are inserted, and
the checkpoint that writes them is timed. The base walks all N rows
again. This PR walks the 10,000 new rows.

| N rows already checkpointed | Base second checkpoint p50 | This PR
second checkpoint p50 |
|---|---|---|
| 10,000 | 3.7 ms | 4.6 ms |
| 100,000 | 11.0 ms | 7.2 ms |
| 250,000 | 23.3 ms | 10.2 ms |
| 500,000 | 44.6 ms | 17.0 ms |
| 1,000,000 | 89.3 ms | 26.1 ms |

The remaining growth in this PR comes from the version sweep in
Finalize, which both builds run over every row. The first checkpoint of
a new store still scans every row, and it now also prunes the dirty keys
it covered. p50 at 1,000,000 rows: 607 ms base, 701 ms this PR. That
cost is paid once per full scan, and only for rows committed after the
store opened.

Tests: `cargo test -p turso_core --lib`, `cargo test --test
integration_tests mvcc`, `cargo test --test integration_tests
checkpoint`. New tests cover a commit that lands between snapshot and
collect followed by a restart, a rolled-back insert, a low row id
committed late, an index updated after a checkpoint, recovery followed
by a first checkpoint, near and far dirty keys with a missing chain, and
prune keeping a key marked again after collect.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Reviewed-by: Pekka Enberg <penberg@iki.fi>

Closes #9157
2026-10-14 19:24:50 +02:00
Turso Agent
177f1e6204 postgres: map schema names in schema.table.column references
Fixes #9890
2026-10-14 17:21:48 +00:00
Pedro Muniz
75a4578711 Merge 'postgres: describe native languages and unsupported object catalogs' from Pedro Muniz
Part 9 of 22 in the pg_dump feature series, stacked on
https://github.com/tursodatabase/turso/pull/9723 (`postgres-pgdump-
function-discovery`). Review this diff against its immediate parent.

Describe the native internal and c function languages through
pg_language, and identify built-in engine functions as internal. Add
empty, read-only catalogs for unsupported operators, operator classes
and families, text-search objects, foreign servers, default ACLs,
conversions, ranges, event triggers, subscriptions, large objects, and
access-method support entries. Empty catalogs do not implement their
associated PostgreSQL features.

This is one of ten smaller layers extracted from the former combined PR
#9701. Catalog system columns and boolean types now come before session
setup. The combined source and existing regression tests are unchanged;
early layers do not claim complete pg_dump support.

Reorganized with Amp under Pedro's direction, preserving the published
combined source and running before/after regressions plus cumulative
checks at every new layer.

Closes #9724
2026-10-14 14:13:41 -03:00
Amp
9f5558113a postgres: move object catalog coverage to sqltests
Exercise language discovery, empty unsupported catalogs, and rejected
catalog writes through the PostgreSQL wire protocol. Keep result column
counts in Rust because SQLtests do not expose result metadata.

Tests: 20 converted cases fail on the parent engine; 63 catalog SQLtests
and 14 catalog API tests pass with the object catalogs.

Amp-Thread-ID: https://ampcode.com/threads/T-01a136e4-bd19-76ac-8b5f-28d83b5dc9c7
Co-authored-by: pedro muniz <pedro.muniz.carlo@gmail.com>
2026-10-14 16:55:31 +00:00
Amp
625eff2fc8 postgres: describe native languages and unsupported object catalogs
Separate this behavior and its existing regression coverage from PR #9701.

Preserve the published combined source while placing catalog columns and
types before dump session setup.

Tests: existing regressions fail without this behavior; cumulative
PostgreSQL integration and server suites pass at this layer.

Amp-Thread-ID: T-01a121dc-2358-77c8-951b-d84ef7dd5a0e
Co-authored-by: pedro muniz <pedro.muniz.carlo@gmail.com>
2026-10-14 16:54:43 +00:00