uqa-engine 0.2.3

Engine: schema-aware table store, catalog restore, transactions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
//
// Unified Query Algebra
//
// Copyright (c) 2023-2026 Cognica, Inc.
//

//! DROP preflight, object removal, and index side effects.

use super::{CatalogIndexRow, ColumnType, DropKind, DropStmt, Engine, SQLError, SQLResult};
use crate::engine_capabilities::RelationResolution;

mod index_dependencies;

pub(in crate::sql) fn run_drop(engine: &Engine, stmt: DropStmt) -> Result<SQLResult, SQLError> {
    if stmt.kind == DropKind::Table {
        for name in &stmt.names {
            if let Some(canonical) = crate::sql::resolve_age_label_relation_name(engine, name)? {
                let relation =
                    crate::RelationIdentity::from_legacy_name(&canonical).map_err(|error| {
                        SQLError::Internal(format!(
                            "resolve AGE label relation `{canonical}` for DROP TABLE: {error}"
                        ))
                    })?;
                return Err(SQLError::Routine {
                    sqlstate: "2BP01".into(),
                    message: format!(
                        "table \"{}\" is for label \"{}\"",
                        relation.name, relation.name
                    ),
                });
            }
        }
    }
    if stmt.kind == DropKind::Index {
        return run_drop_index(engine, stmt);
    }
    if stmt.cascade
        && stmt.kind == DropKind::Schema
        && !only_graph_namespaces(engine, &stmt.names, stmt.if_exists)?
    {
        return Err(SQLError::Unsupported(
            "DROP SCHEMA CASCADE is not supported; no objects were changed".into(),
        ));
    }
    let mut lock_targets = std::collections::BTreeSet::new();
    match stmt.kind {
        DropKind::Table | DropKind::ForeignTable | DropKind::View | DropKind::MaterializedView => {
            let mut table_targets = Vec::new();
            for name in &stmt.names {
                if let Some((canonical, kind)) = engine.try_resolve_visible_relation_kind(name)? {
                    if stmt.kind == DropKind::Table && kind == "table" {
                        table_targets.push(canonical.clone());
                    }
                    lock_targets.insert(canonical);
                }
            }
            if stmt.kind == DropKind::Table {
                let (hierarchy_targets, _) =
                    engine.hierarchy_drop_targets(&table_targets, stmt.cascade);
                lock_targets.extend(hierarchy_targets);
            }
        }
        DropKind::Index => unreachable!("DROP INDEX has a bound execution path"),
        DropKind::Schema => {
            // Dropping a schema removes every relation it owns, including the label relations of a graph namespace, so each of them takes the same AccessExclusive lock a direct DROP would.
            for name in &stmt.names {
                for table in engine
                    .tables_in_schema(name)
                    .map_err(|err| ddl_storage_error("DROP SCHEMA relation lock", err))?
                {
                    lock_targets.insert(format!("{name}.{table}"));
                }
            }
        }
        DropKind::Sequence => {}
    }
    for table in lock_targets {
        engine.lock_relation(&table, crate::row_locks::RelationLockMode::AccessExclusive)?;
    }
    engine.with_implicit_transaction(move |engine| run_drop_inner(engine, stmt))
}

/// `DROP SCHEMA ... CASCADE` is implemented for graph namespaces, whose only
/// dependents are the graph's own label relations, so cascading drops the
/// graph exactly like AGE.
fn only_graph_namespaces(
    engine: &Engine,
    names: &[String],
    if_exists: bool,
) -> Result<bool, SQLError> {
    for name in names {
        let is_graph = engine
            .has_graph(name)
            .map_err(|err| ddl_storage_error("DROP SCHEMA", err))?;
        let is_schema = engine
            .has_schema(name)
            .map_err(|err| ddl_storage_error("DROP SCHEMA", err))?;
        // `IF EXISTS` skips a name that is neither a graph nor a schema, so
        // it must not force the unsupported-CASCADE rejection.
        if if_exists && !is_graph && !is_schema {
            continue;
        }
        if !is_graph || is_schema {
            return Ok(false);
        }
    }
    Ok(!names.is_empty())
}

#[expect(
    clippy::too_many_lines,
    reason = "preserves DDL dependency and action order"
)]
fn run_drop_inner(engine: &Engine, stmt: DropStmt) -> Result<SQLResult, SQLError> {
    match stmt.kind {
        DropKind::Table => {
            let mut tables = Vec::new();
            for name in &stmt.names {
                match engine.try_resolve_visible_relation_kind(name)? {
                    Some((canonical, "table")) => tables.push(canonical),
                    Some((canonical, kind)) => {
                        return Err(SQLError::Unsupported(format!(
                            "DROP TABLE: relation `{canonical}` is a {kind}, not a table"
                        )));
                    }
                    None if stmt.if_exists => {}
                    None => {
                        return Err(SQLError::Unsupported(format!(
                            "DROP TABLE: relation `{name}` does not exist"
                        )));
                    }
                }
            }
            for table in &tables {
                engine.ensure_table_drop_authority(table)?;
            }
            let (tables, dependents) = engine.hierarchy_drop_targets(&tables, stmt.cascade);
            if !dependents.is_empty() {
                return Err(SQLError::Routine {
                    sqlstate: "2BP01".into(),
                    message: format!(
                        "cannot drop table {} because other objects depend on it",
                        tables.join(", ")
                    ),
                });
            }
            if !stmt.cascade {
                let restrict_dependents = engine
                    .try_drop_table_restrict_dependents(&tables)
                    .map_err(|err| ddl_storage_error("DROP TABLE dependency preflight", err))?;
                if !restrict_dependents.is_empty() {
                    return Err(SQLError::Routine {
                        sqlstate: "2BP01".into(),
                        message: format!(
                            "cannot drop table {} because other objects depend on it: {}",
                            tables.join(", "),
                            restrict_dependents.join(", ")
                        ),
                    });
                }
            }
            for table in &tables {
                engine.ensure_no_pending_trigger_events(table, "DROP TABLE")?;
            }
            engine
                .try_drop_tables(&tables, stmt.cascade)
                .map_err(|err| ddl_storage_error("DROP TABLE", err))?;
        }
        DropKind::ForeignTable => {
            let mut foreign_tables = Vec::new();
            let mut seen = std::collections::BTreeSet::new();
            for name in &stmt.names {
                match engine.resolve_visible_relation_kind(name)? {
                    RelationResolution::Found(canonical, "foreign table") => {
                        if seen.insert(canonical.clone()) {
                            foreign_tables.push(canonical);
                        }
                    }
                    RelationResolution::Found(_, _) => {
                        return Err(SQLError::Routine {
                            sqlstate: "42809".into(),
                            message: format!("\"{name}\" is not a foreign table"),
                        });
                    }
                    RelationResolution::MissingSchema(schema) if stmt.if_exists => {
                        engine.push_sql_notice(
                            "NOTICE",
                            &format!("schema \"{schema}\" does not exist, skipping"),
                        );
                    }
                    RelationResolution::MissingRelation if stmt.if_exists => {
                        engine.push_sql_notice(
                            "NOTICE",
                            &format!("foreign table \"{name}\" does not exist, skipping"),
                        );
                    }
                    RelationResolution::MissingSchema(schema) => {
                        return Err(SQLError::Routine {
                            sqlstate: "3F000".into(),
                            message: format!("schema \"{schema}\" does not exist"),
                        });
                    }
                    RelationResolution::MissingRelation => {
                        return Err(SQLError::Routine {
                            sqlstate: "42P01".into(),
                            message: format!("foreign table \"{name}\" does not exist"),
                        });
                    }
                }
            }
            for table in &foreign_tables {
                engine.ensure_foreign_table_drop_authority(table)?;
            }
            let target_names = foreign_tables.iter().cloned().collect();
            let owned_sequences = engine
                .foreign_table_owned_sequence_names(&foreign_tables)
                .map_err(|error| {
                    ddl_storage_error("DROP FOREIGN TABLE sequence ownership", error)
                })?;
            let mut dependents = std::collections::BTreeSet::new();
            for table in &foreign_tables {
                dependents.extend(
                    engine
                        .views_depending_on_relation(table)
                        .map_err(|error| {
                            ddl_storage_error("DROP FOREIGN TABLE dependency preflight", error)
                        })?
                        .into_iter()
                        .map(|view| format!("view {view}")),
                );
            }
            dependents.extend(
                engine
                    .rules_depending_on_relations(&foreign_tables)
                    .map_err(|error| {
                        ddl_storage_error("DROP FOREIGN TABLE dependency preflight", error)
                    })?
                    .into_iter()
                    .map(|(table, rule)| {
                        format!("rule {rule} on table {}", table.qualified_name())
                    }),
            );
            for sequence in &owned_sequences {
                dependents.extend(
                    engine
                        .sequence_external_dependents_for_owner_drop(sequence, &target_names)
                        .map_err(|error| {
                            ddl_storage_error(
                                "DROP FOREIGN TABLE owned-sequence dependency preflight",
                                error,
                            )
                        })?,
                );
            }
            if !stmt.cascade && !dependents.is_empty() {
                return Err(SQLError::Routine {
                    sqlstate: "2BP01".into(),
                    message: format!(
                        "cannot drop foreign table {} because other objects depend on it: {}",
                        foreign_tables.join(", "),
                        dependents.into_iter().collect::<Vec<_>>().join(", ")
                    ),
                });
            }
            if stmt.cascade {
                engine
                    .drop_rules_depending_on_relations_inner(&foreign_tables)
                    .map_err(|error| ddl_storage_error("DROP FOREIGN TABLE CASCADE", error))?;
                engine
                    .drop_views_depending_on_relations(&foreign_tables)
                    .map_err(|error| ddl_storage_error("DROP FOREIGN TABLE CASCADE", error))?;
            }
            for table in foreign_tables {
                let removed = engine.drop_foreign_table_inner(&table).map_err(|error| {
                    SQLError::Internal(format!(
                        "DROP FOREIGN TABLE failed in storage backend: {error}"
                    ))
                })?;
                if !removed {
                    return Err(SQLError::Internal(format!(
                        "foreign table `{table}` disappeared after DROP preflight"
                    )));
                }
            }
            for sequence in owned_sequences {
                engine
                    .drop_owned_sequence(&sequence, stmt.cascade)
                    .map_err(|error| {
                        ddl_storage_error("DROP FOREIGN TABLE owned sequence", error)
                    })?;
            }
        }
        DropKind::Index => unreachable!("DROP INDEX has a bound execution path"),
        DropKind::View | DropKind::MaterializedView => {
            let expected_kind = if stmt.kind == DropKind::View {
                "view"
            } else {
                "materialized view"
            };
            let command = if stmt.kind == DropKind::View {
                "DROP VIEW"
            } else {
                "DROP MATERIALIZED VIEW"
            };
            let mut views = Vec::new();
            for name in &stmt.names {
                match engine.try_resolve_visible_relation_kind(name)? {
                    Some((canonical, kind)) if kind == expected_kind => views.push(canonical),
                    Some((canonical, kind)) => {
                        return Err(SQLError::Routine {
                            sqlstate: "42809".into(),
                            message: format!(
                                "{command}: relation `{canonical}` is a {kind}, not a {expected_kind}"
                            ),
                        });
                    }
                    None if stmt.if_exists => {}
                    None => {
                        return Err(SQLError::Routine {
                            sqlstate: "42P01".into(),
                            message: format!("{command}: relation `{name}` does not exist"),
                        });
                    }
                }
            }
            engine.drop_views(&views, stmt.cascade)?;
        }
        DropKind::Sequence => {
            let mut sequences = Vec::new();
            let mut seen = std::collections::BTreeSet::new();
            for name in &stmt.names {
                match engine.resolve_visible_relation_kind(name)? {
                    RelationResolution::Found(canonical, "sequence") => {
                        if seen.insert(canonical.clone()) {
                            sequences.push(canonical);
                        }
                    }
                    RelationResolution::Found(_canonical, _kind) => {
                        return Err(SQLError::Routine {
                            sqlstate: "42809".into(),
                            message: format!("\"{name}\" is not a sequence"),
                        });
                    }
                    RelationResolution::MissingRelation | RelationResolution::MissingSchema(_)
                        if stmt.if_exists =>
                    {
                        engine.push_sql_notice(
                            "NOTICE",
                            &format!("sequence \"{name}\" does not exist, skipping"),
                        );
                    }
                    RelationResolution::MissingSchema(schema) => {
                        return Err(SQLError::Routine {
                            sqlstate: "3F000".into(),
                            message: format!("schema \"{schema}\" does not exist"),
                        });
                    }
                    RelationResolution::MissingRelation => {
                        return Err(SQLError::Routine {
                            sqlstate: "42P01".into(),
                            message: format!("sequence \"{name}\" does not exist"),
                        });
                    }
                }
            }
            engine.drop_sequences_sql_inner(&sequences, stmt.cascade)?;
        }
        DropKind::Schema => {
            let mut schemas = Vec::new();
            let mut graphs = Vec::new();
            for name in &stmt.names {
                let exists = engine
                    .preflight_drop_schema(name)
                    .map_err(|err| ddl_storage_error("DROP SCHEMA", err))?;
                if exists {
                    schemas.push(name.clone());
                    continue;
                }
                // A named graph owns a namespace of the same name whose
                // label relations always depend on it, exactly like AGE's
                // graph schema: RESTRICT fails and CASCADE drops the graph.
                if engine
                    .has_graph(name)
                    .map_err(|err| ddl_storage_error("DROP SCHEMA", err))?
                {
                    if !stmt.cascade {
                        return Err(SQLError::Routine {
                            sqlstate: "2BP01".into(),
                            message: format!(
                                "cannot drop schema {name} because other objects depend on it"
                            ),
                        });
                    }
                    graphs.push(name.clone());
                } else if !stmt.if_exists {
                    return Err(SQLError::Unsupported(format!(
                        "DROP SCHEMA: schema `{name}` does not exist"
                    )));
                }
            }
            for schema in schemas {
                engine
                    .drop_schema(&schema)
                    .map_err(|err| ddl_storage_error("DROP SCHEMA", err))?;
            }
            for graph in graphs {
                engine
                    .drop_graph(&graph)
                    .map_err(|err| ddl_storage_error("DROP SCHEMA", err))?;
            }
        }
    }
    Ok(SQLResult::empty())
}

fn run_drop_index(engine: &Engine, stmt: DropStmt) -> Result<SQLResult, SQLError> {
    let mut indexes = Vec::new();
    let mut seen = std::collections::BTreeSet::new();
    for requested in &stmt.names {
        match engine.resolve_visible_relation_kind(requested)? {
            RelationResolution::Found(canonical, "index") => {
                let relation = crate::RelationIdentity::from_legacy_name(&canonical)
                    .map_err(SQLError::Internal)?;
                if !seen.insert(relation.clone()) {
                    continue;
                }
                let row = engine
                    .bound_catalog_index(&canonical)
                    .map_err(|error| ddl_storage_error("DROP INDEX", error))?
                    .ok_or_else(|| {
                        SQLError::Internal(format!(
                            "resolved index `{canonical}` has no bound catalog row"
                        ))
                    })?;
                engine.require_index_drop_authority(&row)?;
                if engine
                    .catalog_read_view()
                    .has_constraint_index(&row.relation)
                {
                    return Err(SQLError::Routine {
                        sqlstate: "2BP01".into(),
                        message: format!(
                            "cannot drop index {} because constraint {} on table {} requires it",
                            row.relation.name, row.relation.name, row.table_name
                        ),
                    });
                }
                indexes.push(row);
            }
            RelationResolution::Found(_, _) => {
                return Err(SQLError::Routine {
                    sqlstate: "42809".into(),
                    message: format!("\"{requested}\" is not an index"),
                });
            }
            RelationResolution::MissingSchema(schema) if stmt.if_exists => {
                engine.push_sql_notice(
                    "NOTICE",
                    &format!("schema \"{schema}\" does not exist, skipping"),
                );
            }
            RelationResolution::MissingSchema(schema) => {
                return Err(SQLError::Routine {
                    sqlstate: "3F000".into(),
                    message: format!("schema \"{schema}\" does not exist"),
                });
            }
            RelationResolution::MissingRelation if stmt.if_exists => {
                let local = crate::RelationIdentity::parse_reference(requested)
                    .map_err(SQLError::Internal)?
                    .1;
                engine.push_sql_notice(
                    "NOTICE",
                    &format!("index \"{local}\" does not exist, skipping"),
                );
            }
            RelationResolution::MissingRelation => {
                let local = crate::RelationIdentity::parse_reference(requested)
                    .map_err(SQLError::Internal)?
                    .1;
                return Err(SQLError::Routine {
                    sqlstate: "42704".into(),
                    message: format!("index \"{local}\" does not exist"),
                });
            }
        }
    }
    let dependents = index_dependencies::dependents(engine, &indexes, stmt.cascade)?;
    for row in &indexes {
        engine.lock_relation(
            &row.table_name,
            crate::row_locks::RelationLockMode::AccessExclusive,
        )?;
    }
    engine.with_implicit_transaction(move |engine| {
        for (table, name) in dependents {
            super::alter_table::drop_constraint_dependency(engine, &table, &name)?;
        }
        for row in indexes {
            drop_index_side_effects(engine, &row)?;
            engine
                .try_drop_catalog_index_relation(&row.relation)
                .map_err(|error| ddl_storage_error("DROP INDEX", error))?;
        }
        Ok(SQLResult::empty())
    })
}

pub(super) fn ddl_storage_error(action: &str, err: impl std::error::Error + 'static) -> SQLError {
    let mut source: Option<&(dyn std::error::Error + 'static)> = Some(&err);
    while let Some(error) = source {
        if let Some(error) = error.downcast_ref::<SQLError>() {
            return SQLError::Routine {
                sqlstate: error.sqlstate().unwrap_or("XX000").into(),
                message: error.to_string(),
            };
        }
        source = error.source();
    }
    SQLError::Internal(format!("{action} failed in storage backend: {err}"))
}

fn drop_index_side_effects(engine: &Engine, row: &CatalogIndexRow) -> Result<(), SQLError> {
    if row.index_type.eq_ignore_ascii_case("gin") {
        drop_gin_index_side_effects(engine, row)?;
    } else if row.index_type.eq_ignore_ascii_case("ivf")
        || row.index_type.eq_ignore_ascii_case("hnsw")
    {
        drop_vector_index_side_effects(engine, row)?;
    }
    Ok(())
}

fn catalog_index_columns(row: &CatalogIndexRow, action: &str) -> Result<Vec<String>, SQLError> {
    serde_json::from_str(&row.columns_json).map_err(|e| {
        SQLError::Internal(format!(
            "{action} `{}`: invalid index column metadata: {e}",
            row.relation.qualified_name()
        ))
    })
}

fn drop_gin_index_side_effects(engine: &Engine, row: &CatalogIndexRow) -> Result<(), SQLError> {
    let fields: std::collections::BTreeSet<String> = catalog_index_columns(row, "DROP INDEX")?
        .into_iter()
        .collect();
    let indexes = engine
        .list_catalog_indexes()
        .map_err(|err| ddl_storage_error("DROP INDEX", err))?;

    for field in fields {
        let mut still_referenced = false;
        for candidate in &indexes {
            if candidate.relation == row.relation
                || candidate.table_name != row.table_name
                || !candidate.index_type.eq_ignore_ascii_case("gin")
            {
                continue;
            }
            if catalog_index_columns(candidate, "DROP INDEX")?
                .iter()
                .any(|candidate_field| candidate_field == &field)
            {
                still_referenced = true;
                break;
            }
        }
        if !still_referenced {
            engine
                .drop_fts_field(&row.table_name, &field)
                .map_err(|err| {
                    SQLError::Internal(format!(
                        "DROP INDEX `{}`: failed to remove FTS field `{}`.`{field}`: {err}",
                        row.relation.qualified_name(),
                        row.table_name
                    ))
                })?;
        }
    }
    Ok(())
}

fn drop_vector_index_side_effects(engine: &Engine, row: &CatalogIndexRow) -> Result<(), SQLError> {
    let columns = catalog_index_columns(row, "DROP INDEX")?;
    for col in columns {
        match engine
            .column_type(&row.table_name, &col)
            .map_err(|err| ddl_storage_error("DROP INDEX", err))?
        {
            Some(ColumnType::Vector(dim) | ColumnType::Tensor(dim)) => {
                if !engine
                    .drop_vector_field_index(&row.table_name, col.clone(), dim)
                    .map_err(|err| ddl_storage_error("DROP INDEX vector field", err))?
                {
                    return Err(SQLError::Unsupported(format!(
                        "DROP INDEX `{}`: relation `{}` does not exist",
                        row.relation.qualified_name(),
                        row.table_name
                    )));
                }
                engine
                    .drop_vector_index_metadata(&row.table_name, &col)
                    .map_err(|e| {
                        SQLError::Internal(format!(
                            "DROP INDEX `{}`: failed to drop vector-index metadata for `{}`.`{col}`: {e}",
                            row.relation.qualified_name(), row.table_name
                        ))
                    })?;
            }
            Some(other) => {
                return Err(SQLError::Unsupported(format!(
                    "DROP INDEX `{}`: vector-index column `{}`.`{col}` is no longer VECTOR or TENSOR, got {other:?}",
                    row.relation.qualified_name(), row.table_name
                )));
            }
            None => {
                return Err(SQLError::Unsupported(format!(
                    "DROP INDEX `{}`: column `{}`.`{col}` does not exist",
                    row.relation.qualified_name(),
                    row.table_name
                )));
            }
        }
    }
    Ok(())
}

/// Remove a dependent index after the owning DROP command has checked its authority.
pub(crate) fn drop_index_dependency(
    engine: &Engine,
    relation: &crate::RelationIdentity,
) -> Result<(), SQLError> {
    let row = engine
        .bound_catalog_index(&relation.qualified_name())
        .map_err(|error| ddl_storage_error("DROP INDEX dependency", error))?
        .ok_or_else(|| SQLError::Internal("dependent index disappeared".into()))?;
    drop_index_side_effects(engine, &row)?;
    engine
        .try_drop_catalog_index_relation(relation)
        .map_err(|error| ddl_storage_error("DROP INDEX dependency", error))?;
    Ok(())
}