Files
turso/testing
Pere Diaz Bou 7c96b6d9f9 Merge 'Fix: Drop internal DBSP table when dropping materialized view' from Martin Mauch
# Fix: Clean up DBSP state table when dropping materialized views
## Problem
When dropping a materialized view, the internal DBSP state table (e.g.,
`__turso_internal_dbsp_state_v1_view_name`) and its automatic primary
key index were not being properly cleaned up. This caused two issues:
1. **Persistent schema entries**: The DBSP table and index entries
remained in `sqlite_schema` after dropping the view
2. **In-memory schema inconsistency**: The DBSP table remained in the
in-memory schema's `tables` HashMap, causing "table already exists"
errors when trying to recreate a materialized view with the same name
## Root Cause
The issue had two parts:
1. **Missing sqlite_schema cleanup**: The `translate_drop_view` function
deleted the view entry from `sqlite_schema` but didn't delete the
associated DBSP state table and index entries
2. **Missing in-memory schema cleanup**: The `remove_view` function
removed the materialized view from the in-memory schema but didn't
remove the DBSP state table and its indexes
## Solution
### Changes in `core/translate/view.rs`
- Added a second pass loop in `translate_drop_view` to scan
`sqlite_schema` and delete DBSP table and index entries
- The loop checks for entries matching the DBSP table name pattern
(`__turso_internal_dbsp_state_v{version}_{view_name}`) and the automatic
index name pattern (`sqlite_autoindex___turso_internal_dbsp_state_v{vers
ion}_{view_name}_1`)
- Registers for comparison values are allocated outside the loop for
efficiency
- Column registers are reused across loop iterations
### Changes in `core/schema.rs`
- Updated `remove_view` to also remove the DBSP state table and its
indexes from the in-memory schema's `tables` HashMap and `indexes`
collection
- This ensures consistency between the persistent schema
(`sqlite_schema`) and the in-memory schema
### Tests Added
Added two new test cases in `testing/materialized_views.test`:
1. **`matview-drop-cleans-up-dbsp-table`**: Explicitly verifies that
after dropping a materialized view:
   - The view entry is removed from `sqlite_schema`
   - The DBSP state table entry is removed from `sqlite_schema`
   - The DBSP state index entry is removed from `sqlite_schema`
2. **`matview-recreate-after-drop`**: Verifies that a materialized view
can be successfully recreated after being dropped, which implicitly
tests that all underlying resources (including DBSP tables) are properly
cleaned up
## Testing
- All existing materialized view tests pass
- New tests specifically verify the cleanup behavior
- Manual testing confirms that materialized views can be dropped and
recreated without errors
## Related
This fix ensures that materialized views can be safely dropped and
recreated, resolving issues where the DBSP state table would persist and
cause conflicts.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3928
2025-11-12 17:16:04 +01:00
..
2025-11-09 11:35:57 -05:00
2025-08-02 13:00:18 +03:00
2025-07-15 16:44:11 +03:00
2024-08-03 12:16:34 +03:00
2025-09-28 21:16:33 +05:30
2025-10-12 15:58:10 +05:30
2025-10-30 11:38:56 +02:00
2025-02-09 22:01:33 +04:00
2025-10-02 21:49:33 +03:00
2025-10-30 11:38:56 +02:00
2025-10-30 11:38:56 +02:00
2025-10-30 11:38:56 +02:00
2025-08-01 15:44:56 +03:00
2025-08-05 21:18:52 -07:00
2025-10-30 11:38:56 +02:00
2025-06-20 15:59:03 -03:00
2025-10-30 11:38:56 +02:00
2025-10-30 11:38:56 +02:00
2025-05-08 22:22:55 +08:00
2025-09-17 14:50:15 +07:00
2025-09-01 11:39:43 -04:00
2025-10-15 09:41:44 +03:00
2025-08-11 12:13:47 -04:00
2025-08-01 15:44:56 +03:00
2025-10-12 22:23:04 +05:30
2025-08-11 08:42:08 -03:00
2025-10-30 11:38:56 +02:00
2025-09-30 22:39:55 +04:00
2025-10-13 16:14:29 -03:00
2025-08-15 21:06:30 +02:00
2025-09-13 11:12:44 +02:00

Turso Testing

Testing Extensions

When adding tests for extensions, please follow these guidelines:

  • Tests that verify the internal logic or behavior of a particular extension should go into cli_tests/extensions.py.
  • Tests that verify how extensions interact with the database engine, such as virtual table handling, should be written in TCL (see vtab.test as an example).

To check which extensions are available in TCL, or to add a new one, refer to the tester.tcl file and look at the extension_map.