Skip to content

Commit b8be591

Browse files
authored
Merge pull request #8445 from FirebirdSQL/work/schema
Feature #1113 - SQL Schemas
2 parents 1f226fc + 1c09a8e commit b8be591

File tree

234 files changed

+19056
-10051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+19056
-10051
lines changed

builds/install/misc/replication.conf

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ database
1111
#
1212
# plugin =
1313

14+
# Pattern (regular expression) that defines what schemas must be included into
15+
# replication. By default, tables from all schemas are replicated.
16+
#
17+
# include_schema_filter =
18+
19+
# Pattern (regular expression) that defines what schemas must be excluded from
20+
# replication. By default, tables from all schemas are replicated.
21+
#
22+
# exclude_schema_filter =
23+
1424
# Pattern (regular expression) that defines what tables must be included into
1525
# replication. By default, all tables are replicated.
1626
#
17-
# include_filter =
27+
# include_filter =
1828

1929
# Pattern (regular expression) that defines what tables must be excluded from
2030
# replication. By default, all tables are replicated.
2131
#
22-
# exclude_filter =
32+
# exclude_filter =
2333

2434
# Boolean parameters describing how replication errors must be handled.
2535
#
@@ -42,20 +52,20 @@ database
4252

4353
# Directory to store replication journal files.
4454
#
45-
# journal_directory =
55+
# journal_directory =
4656

4757
# Prefix for replication journal file names. It will be automatically suffixed
4858
# with an ordinal sequential number. If not specified, database filename
4959
# (without path) is used as a prefix.
5060
#
51-
# journal_file_prefix =
61+
# journal_file_prefix =
5262

5363
# Maximum allowed size for a single replication segment.
5464
#
5565
# journal_segment_size = 16777216 # 16MB
5666

5767
# Maximum allowed number of full replication segments. Once this limit is reached,
58-
# the replication process is temporarily delayed to allow the archiving to catch up.
68+
# the replication process is temporarily delayed to allow the archiving to catch up.
5969
# If any of the full segments is not archived during one minute,
6070
# the replication fails with an error.
6171
#
@@ -76,7 +86,7 @@ database
7686
# Directory to store archived replication segments.
7787
# It also defines the $(archpathname) substitution macro (see below).
7888
#
79-
# journal_archive_directory =
89+
# journal_archive_directory =
8090

8191
# Program (complete command line with arguments) that is executed when some
8292
# replication segment gets full and needs archiving.
@@ -97,7 +107,7 @@ database
97107
# or
98108
# Windows: "copy $(pathname) $(archivepathname)"
99109
#
100-
# journal_archive_command =
110+
# journal_archive_command =
101111

102112
# Timeout, in seconds, to wait until incomplete segment is scheduled for archiving.
103113
# It allows to minimize the replication gap if the database is modified rarely.
@@ -121,7 +131,7 @@ database
121131
#
122132
# Multiple entries are allowed (for different synchronous replicas).
123133
#
124-
# sync_replica =
134+
# sync_replica =
125135
#
126136
# It's also possible to configure replicas as separate sub-sections, e.g.:
127137
#
@@ -175,13 +185,13 @@ database
175185

176186
# Directory to search for the journal files to be replicated.
177187
#
178-
# journal_source_directory =
188+
# journal_source_directory =
179189

180190
# Filter to limit replication to the particular source database (based on its GUID).
181191
# Expected format: "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
182192
# Note that double quotes are mandatory, as well as curly braces.
183193
#
184-
# source_guid =
194+
# source_guid =
185195

186196
# If enabled, replication.log contains the detailed log of operations performed
187197
# by the replication server. Otherwise (by default), only errors and warnings are logged.
@@ -202,6 +212,14 @@ database
202212
# then reconnects back and tries to re-apply the latest segments from the point of failure.
203213
#
204214
# apply_error_timeout = 60
215+
216+
# Schema search path for compatibility with Firebird versions below 6.0
217+
#
218+
# Firebird master databases below v6 has no schemas, so use this search path in the replica to
219+
# locate the objects.
220+
# Used only with asynchronous replication.
221+
#
222+
# schema_search_path =
205223
}
206224

207225
#

builds/make.new/config/install-sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# install - install a program, script, or datafile
33

4-
scriptversion=2023-11-23.18; # UTC
4+
scriptversion=2024-06-19.01; # UTC
55

66
# This originates from X11R5 (mit/util/scripts/install.sh), which was
77
# later released in X11R6 (xc/config/util/install.sh) with the
@@ -170,7 +170,7 @@ while test $# -ne 0; do
170170

171171
-T) is_target_a_directory=never;;
172172

173-
--version) echo "$0 $scriptversion"; exit $?;;
173+
--version) echo "$0 (GNU Automake) $scriptversion"; exit $?;;
174174

175175
--) shift
176176
break;;
@@ -345,15 +345,15 @@ do
345345
' 0
346346

347347
# Because "mkdir -p" follows existing symlinks and we likely work
348-
# directly in world-writeable /tmp, make sure that the '$tmpdir'
348+
# directly in world-writable /tmp, make sure that the '$tmpdir'
349349
# directory is successfully created first before we actually test
350350
# 'mkdir -p'.
351351
if (umask $mkdir_umask &&
352352
$mkdirprog $mkdir_mode "$tmpdir" &&
353353
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
354354
then
355355
if test -z "$dir_arg" || {
356-
# Check for POSIX incompatibilities with -m.
356+
# Check for POSIX incompatibility with -m.
357357
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
358358
# other-writable bit of parent directory when it shouldn't.
359359
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.

builds/win32/msvc15/common.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<ClInclude Include="..\..\..\src\common\classes\NoThrowTimeStamp.h" />
154154
<ClInclude Include="..\..\..\src\common\classes\objects_array.h" />
155155
<ClInclude Include="..\..\..\src\common\classes\ParsedList.h" />
156-
<ClInclude Include="..\..\..\src\common\classes\QualifiedName.h" />
156+
<ClInclude Include="..\..\..\src\common\classes\QualifiedMetaString.h" />
157157
<ClInclude Include="..\..\..\src\common\classes\RefCounted.h" />
158158
<ClInclude Include="..\..\..\src\common\classes\RefMutex.h" />
159159
<ClInclude Include="..\..\..\src\common\classes\rwlock.h" />

builds/win32/msvc15/common.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,6 @@
449449
<ClInclude Include="..\..\..\src\common\classes\objects_array.h">
450450
<Filter>headers</Filter>
451451
</ClInclude>
452-
<ClInclude Include="..\..\..\src\common\classes\QualifiedName.h">
453-
<Filter>headers</Filter>
454-
</ClInclude>
455452
<ClInclude Include="..\..\..\src\common\classes\RefCounted.h">
456453
<Filter>headers</Filter>
457454
</ClInclude>
@@ -611,6 +608,9 @@
611608
<ClInclude Include="..\..\..\src\common\classes\ParsedList.h">
612609
<Filter>headers</Filter>
613610
</ClInclude>
611+
<ClInclude Include="..\..\..\src\common\classes\QualifiedMetaString.h">
612+
<Filter>headers</Filter>
613+
</ClInclude>
614614
<ClInclude Include="..\..\..\src\common\Int128.h">
615615
<Filter>headers</Filter>
616616
</ClInclude>

builds/win32/msvc15/common_test.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@
262262
<ClCompile Include="..\..\..\src\common\tests\StringTest.cpp" />
263263
<ClCompile Include="..\..\..\src\common\classes\tests\AlignerTest.cpp" />
264264
<ClCompile Include="..\..\..\src\common\classes\tests\ArrayTest.cpp" />
265+
<ClCompile Include="..\..\..\src\common\classes\tests\ClumpletTest.cpp" />
265266
<ClCompile Include="..\..\..\src\common\classes\tests\DoublyLinkedListTest.cpp" />
267+
<ClCompile Include="..\..\..\src\common\classes\tests\MetaStringTest.cpp" />
268+
<ClCompile Include="..\..\..\src\common\classes\tests\QualifiedMetaStringTest.cpp" />
269+
<ClCompile Include="..\..\..\src\common\classes\tests\VectorTest.cpp" />
266270
<ClCompile Include="..\..\..\src\yvalve\gds.cpp" />
267271
</ItemGroup>
268272
<ItemGroup>

builds/win32/msvc15/common_test.vcxproj.filters

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,21 @@
3030
<ClCompile Include="..\..\..\src\common\classes\tests\ArrayTest.cpp">
3131
<Filter>source</Filter>
3232
</ClCompile>
33+
<ClCompile Include="..\..\..\src\common\classes\tests\ClumpletTest.cpp">
34+
<Filter>source</Filter>
35+
</ClCompile>
3336
<ClCompile Include="..\..\..\src\common\classes\tests\DoublyLinkedListTest.cpp">
3437
<Filter>source</Filter>
3538
</ClCompile>
39+
<ClCompile Include="..\..\..\src\common\classes\tests\MetaStringTest.cpp">
40+
<Filter>source</Filter>
41+
</ClCompile>
42+
<ClCompile Include="..\..\..\src\common\classes\tests\QualifiedMetaStringTest.cpp">
43+
<Filter>source</Filter>
44+
</ClCompile>
45+
<ClCompile Include="..\..\..\src\common\classes\tests\VectorTest.cpp">
46+
<Filter>source</Filter>
47+
</ClCompile>
3648
<ClCompile Include="..\..\..\src\yvalve\gds.cpp">
3749
<Filter>source</Filter>
3850
</ClCompile>
@@ -43,4 +55,4 @@
4355
<Filter>source</Filter>
4456
</ClCompile>
4557
</ItemGroup>
46-
</Project>
58+
</Project>

doc/README.replication.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ ALTER DATABASE EXCLUDE ALL FROM PUBLICATION
4747
-- to disable replication of specific tables:
4848
ALTER DATABASE EXCLUDE TABLE T1, T2, T3 FROM PUBLICATION
4949

50-
Tables enabled for replicated can be additionally filtered using two settings in the configuration file: include\_filter and exclude\_filter. They are regular expressions that are applied to table names and define rules for inclusion table\(s\) into the replication set or excluding them from the replication set.
50+
Tables enabled for replicated can be additionally filtered using four settings in the configuration file: include\_schema\_filter, exclude\_schema\_filter, include\_filter and exclude\_filter.
51+
They are regular expressions that are applied to schema and table names and define rules for inclusion table\(s\) into the replication set or excluding them from the replication set.
5152

5253
Synchronous replication can be turned on using the sync\_replica setting \(multiple entries are allowed\). It must specify a connection string to the replica database, prefixed with username/password. In SuperServer and SuperClassic architectures, replica database is being internally attached when the first user gets connected to the master database and detached when the last user disconnects from the master database. In Classic Server architecture, every server process keeps an active connection to the replica database.
5354

doc/sql.extensions/README.ddl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ With support for various system privileges in engine it's getting very convenien
569569
rights to users already having specific system privilege. Therefore appropriate grantee type is
570570
suppoprted now. Example:
571571

572-
GRANT ALL ON PLG$SRP_VIEW TO SYSTEM PRIVILEGE USER_MANAGEMENT
572+
GRANT ALL ON PLG$SRP.PLG$SRP_VIEW TO SYSTEM PRIVILEGE USER_MANAGEMENT
573573

574574
Grants all rights to view (used in SRP management plugin) to users having USER_MANAGEMENT privilege.
575575

@@ -715,6 +715,6 @@ ALTER TABLE <table> ADD CONSTRAINT [IF NOT EXISTS] <constraint name> ...
715715
CREATE [UNIQUE] [ASC[ENDING] | DESC[ENDING]]
716716
INDEX indexname [{ACTIVE | INACTIVE}]
717717
ON tablename {(col [, col ...]) | COMPUTED BY (<expression>)}
718-
[WHERE <search_condition>]
718+
[WHERE <search_condition>]
719719

720720
'isql -x' generates script accordingly.

doc/sql.extensions/README.ddl_triggers.txt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ DDL_TRIGGER context namespace:
119119
- EVENT_TYPE: event type (CREATE, ALTER, DROP)
120120
- OBJECT_TYPE: object type (TABLE, VIEW, etc)
121121
- DDL_EVENT: event name (<ddl event item>), where <ddl_event_item> is EVENT_TYPE || ' ' || OBJECT_TYPE
122+
- SCHEMA_NAME: object's schema name
122123
- OBJECT_NAME: metadata object name
123124
- OLD_OBJECT_NAME: metadata object name before a rename
124125
- NEW_OBJECT_NAME: metadata object name after a rename
@@ -294,51 +295,51 @@ commit;
294295

295296
select id, ddl_event, object_name, old_object_name, new_object_name, sql_text, ok from ddl_log order by id;
296297

297-
ID DDL_EVENT OBJECT_NAME OLD_OBJECT_NAME NEW_OBJECT_NAME SQL_TEXT OK
298-
===================== ========================= =============================== =============================== =============================== ================= ======
299-
2 CREATE TABLE T1 <null> <null> 80:0 Y
298+
ID DDL_EVENT OBJECT_NAME OLD_OBJECT_NAME NEW_OBJECT_NAME SQL_TEXT OK
299+
===================== ========================= =============================== =============================== =============================== ================= ======
300+
2 CREATE TABLE T1 <null> <null> 80:0 Y
300301
==============================================================================
301-
SQL_TEXT:
302+
SQL_TEXT:
302303
recreate table t1 (
303304
n1 integer,
304305
n2 integer
305306
)
306307
==============================================================================
307-
3 CREATE TABLE T1 <null> <null> 80:1 N
308+
3 CREATE TABLE T1 <null> <null> 80:1 N
308309
==============================================================================
309-
SQL_TEXT:
310+
SQL_TEXT:
310311
create table t1 (
311312
n1 integer,
312313
n2 integer
313314
)
314315
==============================================================================
315-
4 DROP TABLE T1 <null> <null> 80:2 Y
316+
4 DROP TABLE T1 <null> <null> 80:2 Y
316317
==============================================================================
317-
SQL_TEXT:
318+
SQL_TEXT:
318319
recreate table t1 (
319320
n integer
320321
)
321322
==============================================================================
322-
5 CREATE TABLE T1 <null> <null> 80:3 Y
323+
5 CREATE TABLE T1 <null> <null> 80:3 Y
323324
==============================================================================
324-
SQL_TEXT:
325+
SQL_TEXT:
325326
recreate table t1 (
326327
n integer
327328
)
328329
==============================================================================
329-
6 CREATE DOMAIN DOM1 <null> <null> 80:4 Y
330+
6 CREATE DOMAIN DOM1 <null> <null> 80:4 Y
330331
==============================================================================
331-
SQL_TEXT:
332+
SQL_TEXT:
332333
create domain dom1 as integer
333334
==============================================================================
334-
7 ALTER DOMAIN DOM1 <null> <null> 80:5 Y
335+
7 ALTER DOMAIN DOM1 <null> <null> 80:5 Y
335336
==============================================================================
336-
SQL_TEXT:
337+
SQL_TEXT:
337338
alter domain dom1 type bigint
338339
==============================================================================
339-
8 ALTER DOMAIN DOM1 DOM1 DOM2 80:6 Y
340+
8 ALTER DOMAIN DOM1 DOM1 DOM2 80:6 Y
340341
==============================================================================
341-
SQL_TEXT:
342+
SQL_TEXT:
342343
alter domain dom1 to dom2
343344
==============================================================================
344345

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Name resolution (FB 6.0)
2+
3+
With the introduction of schemas in Firebird 6.0, the syntax `<name>.<name>` - used for tables, views, procedures,
4+
and functions (both standalone and packaged) - introduces ambiguity when resolving object names using the schema
5+
search path. The ambiguity arises between:
6+
7+
- `<schema>.<object>` (a schema and its object)
8+
- `<package>.<object>` (a package and its object)
9+
10+
This document focuses on name resolution rules for tables, views, procedures, and functions within queries and
11+
code blocks.
12+
13+
## Scope specifier (`%`)
14+
15+
To resolve these ambiguities, Firebird introduces a **scope specifier**, represented by the `%` symbol. This
16+
allows unambiguous referencing of objects.
17+
18+
### Syntax
19+
20+
```sql
21+
<name> % { SCHEMA | PACKAGE } . <name>
22+
```
23+
24+
### Examples
25+
26+
```sql
27+
select *
28+
from plg$profiler%schema.plg$prof_sessions;
29+
30+
execute procedure rdb$profiler%package.pause_session;
31+
32+
call rdb$profiler%package.pause_session();
33+
34+
select rdb$time_zone_util%package.database_version()
35+
from system%schema.rdb$database;
36+
37+
select *
38+
from rdb$time_zone_util%package.transitions('America/Sao_Paulo', timestamp '2017-01-01', timestamp '2019-01-01');
39+
```
40+
41+
## Detailed name resolution rules
42+
43+
Firebird resolves object names following a structured sequence of rules. Once an object is located, the resolution
44+
process halts, ensuring no ambiguity errors occur.
45+
46+
- **`name1.name2.name3`**
47+
1. Look for routine `name3` inside package `name2`, inside schema `name1`.
48+
49+
- **`name1%schema.name2`**
50+
1. Look for object `name2` inside schema `name1`.
51+
52+
- **`name1%package.name2`**
53+
1. Look for object `name2` inside a package `name1` using the schema search path.
54+
55+
- **`name1.name2`**
56+
1. If inside a package named `name1`, look for routine `name2` in the same package.
57+
2. Look in schema `name1` for object `name2`.
58+
3. Look for object `name2` inside a package `name1` using the schema search path.
59+
60+
- **`name`**
61+
1. Look for subroutine `name`.
62+
2. If inside a package, look for routine `name` in the same package.
63+
3. Look for object `name` using the schema search path.
64+
65+
> **_Note:_** Object resolution also depends on the context in which they are used. For example, in
66+
`select * from name1.name2`, `name2` could be a table, view, or procedure. However, in
67+
`execute procedure name1.name2`, `name2` must be a procedure. This distinction means that an `execute procedure`
68+
command versus a `select` command can resolve to different objects.

0 commit comments

Comments
 (0)