# Design: Function Registry Cache Coherence on DROP DATABASE

When a database is dropped, the session's function (and table function) registry cache must be cleared for that database so resolution does not see stale entries. Branch: **SPARK-55982-cache-coherence**.

---

## 1. Goal

When a database is dropped, any functions (and table functions) cached for that database in the session's function registries must be removed so that subsequent resolution does not see stale entries.

---

## 2. Rule

Dropping a database must remove all cached function (and table function) entries for that database from the session's registries.

---

## 3. API

`FunctionRegistryBase` (and implementations) expose:

- `dropFunctionsInDatabase(db: String): Unit`

Implementations (e.g. `SimpleFunctionRegistryBase`) clear any registered function whose database equals `db`. `EmptyFunctionRegistryBase` implements it as a no-op.

---

## 4. Invocation

In `SessionCatalog.dropDatabase`, before delegating to the external catalog to drop the database, the session catalog calls:

- `functionRegistry.dropFunctionsInDatabase(dbName)`
- `tableFunctionRegistry.dropFunctionsInDatabase(dbName)`

whenever the database exists (not only when cascade). This keeps the in-memory registries consistent with the set of existing databases.

---

## 5. Key Code Locations

| Area | Path |
|------|------|
| Session catalog | `sql/catalyst/.../SessionCatalog.scala` — `dropDatabase` (calls `dropFunctionsInDatabase`) |
| Registry API | `sql/catalyst/.../FunctionRegistry.scala` — `FunctionRegistryBase.dropFunctionsInDatabase`, `SimpleFunctionRegistryBase`, `EmptyFunctionRegistryBase` |

---

## 6. Tests

**SessionCatalogSuite** — two tests:

- Drop database clears **function** registry cache (cache coherence).
- Drop database clears **table function** registry cache (cache coherence).

Both pre-populate the registry for a database, drop that database, then assert the function is no longer in the registry.
