Skip to content

Commit d377cb2

Browse files
committed
SYSTEM schema should always be in the search path (#8605).
1 parent 5b41342 commit d377cb2

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

doc/sql.extensions/README.schemas.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ you can reset the current search path to its initial configuration with the `ALT
7676

7777
Nonexistent schemas can be included in the search path but are ignored during name resolution.
7878

79+
If `SYSTEM` is not included in the schema list, it is automatically added as the last schema in the search path.
80+
7981
The first existing schema in the search path is referred to as the **current schema** and is exclusively used in some
8082
operations.
8183

@@ -103,7 +105,7 @@ create or alter function F1 returns integer as begin end;
103105
grant create table to user USER1;
104106
```
105107

106-
For `ALTER`, `DROP`, and others statements, the system searches for the specified object across all schemas in the
108+
For `ALTER`, `DROP`, and others statements, Firebird searches for the specified object across all schemas in the
107109
search path. The reference is bound to the first matching object found. If no matching object exists in any schema, an
108110
error is raised.
109111

@@ -133,8 +135,7 @@ In this case, the search path is used to locate `TABLE1`, `DOMAIN1`, and `TABLE2
133135

134136
For DDL statements, the search path operates similarly, but with a subtle difference. Once the object being created or
135137
modified is bound to a schema during statement preparation, the search path is implicitly and temporarily modified.
136-
This adjustment sets the search path to the schema of the object. Additionally, if the `SYSTEM` schema was already
137-
present in the search path, it is appended as the last schema.
138+
This adjustment sets the search path to the schema of the object with `SYSTEM` added as the final schema in the path.
138139

139140
```sql
140141
create schema SCHEMA1;
@@ -198,8 +199,8 @@ grant select on table SCHEMA1.TABLE1 to user USER2;
198199
## The SYSTEM schema
199200

200201
All system schema-bound objects (e.g., `RDB$*` and `MON$*`) are now created in a dedicated schema called `SYSTEM`.
201-
The `SYSTEM` schema has a default `USAGE` permission granted to `PUBLIC` and is included in the default search path.
202-
This ensures backward compatibility with previous Firebird versions.
202+
The `SYSTEM` schema has a default `USAGE` permission granted to `PUBLIC` and is automatically included in the
203+
search path. This ensures backward compatibility with previous Firebird versions.
203204

204205
While the `SYSTEM` schema allows operations like index creation and manipulation of those indexes, it is otherwise
205206
locked for DDL changes. Modifying objects within the `SYSTEM` schema through DDL operations is strongly discouraged.
@@ -265,6 +266,8 @@ schema exists, it returns `NULL`.
265266
SET SEARCH_PATH TO <schema name> [, <schema name>]...
266267
```
267268

269+
If `SYSTEM` is not included in the schema list, it is automatically added as the last schema in the search path.
270+
268271
### RDB$GET_CONTEXT
269272

270273
#### CURRENT_SCHEMA (SYSTEM)
@@ -626,8 +629,7 @@ slave side. This allows mapping database objects to a specific schema using a se
626629
## System packages and functions
627630

628631
Firebird includes system packages such as `RDB$TIME_ZONE_UTIL`, `RDB$PROFILER`, and others. These system packages
629-
are now located in the `SYSTEM` schema. If the `SYSTEM` schema is not included in the search path, their usage
630-
requires explicit qualification with `SYSTEM`, as with any other object bound to the `SYSTEM` schema.
632+
are now located in the `SYSTEM` schema.
631633

632634
In contrast, Firebird also provides non-packaged built-in functions like `RDB$GET_CONTEXT`, `ABS`, and `DATEDIFF`.
633635
These functions are not listed in the database metadata (`RDB$FUNCTIONS`) and neither require nor accept the

src/common/classes/objects_array.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ namespace Firebird
453453
return false;
454454
}
455455

456+
bool exist(const T& item) const
457+
{
458+
size_type pos; // ignored
459+
return find(item, pos);
460+
}
461+
456462
private:
457463
void add(const ObjectsArray<T, A>& o)
458464
{

src/dsql/StmtNodes.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10412,8 +10412,18 @@ void SetSearchPathNode::execute(thread_db* tdbb, DsqlRequest* /*request*/, jrd_t
1041210412
auto newSearchPath = makeRef(
1041310413
FB_NEW_POOL(*attachment->att_pool) AnyRef<ObjectsArray<MetaString>>(*attachment->att_pool));
1041410414

10415+
bool hasSystem = false;
10416+
1041510417
for (const auto& schema : *schemas)
10418+
{
10419+
if (schema == SYSTEM_SCHEMA)
10420+
hasSystem = true;
10421+
1041610422
newSearchPath->add(schema);
10423+
}
10424+
10425+
if (!hasSystem)
10426+
newSearchPath->add(SYSTEM_SCHEMA);
1041710427

1041810428
attachment->att_schema_search_path = std::move(newSearchPath);
1041910429
}

src/jrd/jrd.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7435,6 +7435,8 @@ void DatabaseOptions::get(const UCHAR* dpb, FB_SIZE_T dpb_length, bool& invalid_
74357435
case isc_dpb_search_path:
74367436
getString(rdr, tempStr);
74377437
MetaString::parseList(tempStr, dpb_schema_search_path);
7438+
if (!dpb_schema_search_path.exist(SYSTEM_SCHEMA))
7439+
dpb_schema_search_path.add(SYSTEM_SCHEMA);
74387440
break;
74397441

74407442
case isc_dpb_blr_request_search_path:

0 commit comments

Comments
 (0)