Skip to content

Feature #1113 - SQL Schemas #8445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions builds/install/misc/replication.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ database
#
# plugin =

# Pattern (regular expression) that defines what schemas must be included into
# replication. By default, tables from all schemas are replicated.
#
# include_schema_filter =

# Pattern (regular expression) that defines what schemas must be excluded from
# replication. By default, tables from all schemas are replicated.
#
# exclude_schema_filter =

# Pattern (regular expression) that defines what tables must be included into
# replication. By default, all tables are replicated.
#
# include_filter =
# include_filter =

# Pattern (regular expression) that defines what tables must be excluded from
# replication. By default, all tables are replicated.
#
# exclude_filter =
# exclude_filter =

# Boolean parameters describing how replication errors must be handled.
#
Expand All @@ -42,20 +52,20 @@ database

# Directory to store replication journal files.
#
# journal_directory =
# journal_directory =

# Prefix for replication journal file names. It will be automatically suffixed
# with an ordinal sequential number. If not specified, database filename
# (without path) is used as a prefix.
#
# journal_file_prefix =
# journal_file_prefix =

# Maximum allowed size for a single replication segment.
#
# journal_segment_size = 16777216 # 16MB

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

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

# Timeout, in seconds, to wait until incomplete segment is scheduled for archiving.
# It allows to minimize the replication gap if the database is modified rarely.
Expand All @@ -121,7 +131,7 @@ database
#
# Multiple entries are allowed (for different synchronous replicas).
#
# sync_replica =
# sync_replica =
#
# It's also possible to configure replicas as separate sub-sections, e.g.:
#
Expand Down Expand Up @@ -175,13 +185,13 @@ database

# Directory to search for the journal files to be replicated.
#
# journal_source_directory =
# journal_source_directory =

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

# If enabled, replication.log contains the detailed log of operations performed
# by the replication server. Otherwise (by default), only errors and warnings are logged.
Expand All @@ -202,6 +212,14 @@ database
# then reconnects back and tries to re-apply the latest segments from the point of failure.
#
# apply_error_timeout = 60

# Schema search path for compatibility with Firebird versions below 6.0
#
# Firebird master databases below v6 has no schemas, so use this search path in the replica to
# locate the objects.
# Used only with asynchronous replication.
#
# schema_search_path =
}

#
Expand Down
2 changes: 1 addition & 1 deletion builds/win32/msvc15/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<ClInclude Include="..\..\..\src\common\classes\NoThrowTimeStamp.h" />
<ClInclude Include="..\..\..\src\common\classes\objects_array.h" />
<ClInclude Include="..\..\..\src\common\classes\ParsedList.h" />
<ClInclude Include="..\..\..\src\common\classes\QualifiedName.h" />
<ClInclude Include="..\..\..\src\common\classes\QualifiedMetaString.h" />
<ClInclude Include="..\..\..\src\common\classes\RefCounted.h" />
<ClInclude Include="..\..\..\src\common\classes\RefMutex.h" />
<ClInclude Include="..\..\..\src\common\classes\rwlock.h" />
Expand Down
6 changes: 3 additions & 3 deletions builds/win32/msvc15/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,6 @@
<ClInclude Include="..\..\..\src\common\classes\objects_array.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\common\classes\QualifiedName.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\common\classes\RefCounted.h">
<Filter>headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -611,6 +608,9 @@
<ClInclude Include="..\..\..\src\common\classes\ParsedList.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\common\classes\QualifiedMetaString.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\common\Int128.h">
<Filter>headers</Filter>
</ClInclude>
Expand Down
6 changes: 5 additions & 1 deletion builds/win32/msvc15/common_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@
<ClCompile Include="..\..\..\src\common\tests\StringTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\AlignerTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\ArrayTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\ClumpletTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\DoublyLinkedListTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\MetaStringTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\QualifiedMetaStringTest.cpp" />
<ClCompile Include="..\..\..\src\common\classes\tests\VectorTest.cpp" />
<ClCompile Include="..\..\..\src\yvalve\gds.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -197,4 +201,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
14 changes: 13 additions & 1 deletion builds/win32/msvc15/common_test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@
<ClCompile Include="..\..\..\src\common\classes\tests\ArrayTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\classes\tests\ClumpletTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\classes\tests\DoublyLinkedListTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\classes\tests\MetaStringTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\classes\tests\QualifiedMetaStringTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\common\classes\tests\VectorTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\yvalve\gds.cpp">
<Filter>source</Filter>
</ClCompile>
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion doc/README.replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ ALTER DATABASE EXCLUDE ALL FROM PUBLICATION
-- to disable replication of specific tables:
ALTER DATABASE EXCLUDE TABLE T1, T2, T3 FROM PUBLICATION

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.
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.
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.

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.

Expand Down
4 changes: 2 additions & 2 deletions doc/sql.extensions/README.ddl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ With support for various system privileges in engine it's getting very convenien
rights to users already having specific system privilege. Therefore appropriate grantee type is
suppoprted now. Example:

GRANT ALL ON PLG$SRP_VIEW TO SYSTEM PRIVILEGE USER_MANAGEMENT
GRANT ALL ON PLG$SRP.PLG$SRP_VIEW TO SYSTEM PRIVILEGE USER_MANAGEMENT

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

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

'isql -x' generates script accordingly.
33 changes: 17 additions & 16 deletions doc/sql.extensions/README.ddl_triggers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ DDL_TRIGGER context namespace:
- EVENT_TYPE: event type (CREATE, ALTER, DROP)
- OBJECT_TYPE: object type (TABLE, VIEW, etc)
- DDL_EVENT: event name (<ddl event item>), where <ddl_event_item> is EVENT_TYPE || ' ' || OBJECT_TYPE
- SCHEMA_NAME: object's schema name
- OBJECT_NAME: metadata object name
- OLD_OBJECT_NAME: metadata object name before a rename
- NEW_OBJECT_NAME: metadata object name after a rename
Expand Down Expand Up @@ -294,51 +295,51 @@ commit;

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

ID DDL_EVENT OBJECT_NAME OLD_OBJECT_NAME NEW_OBJECT_NAME SQL_TEXT OK
===================== ========================= =============================== =============================== =============================== ================= ======
2 CREATE TABLE T1 <null> <null> 80:0 Y
ID DDL_EVENT OBJECT_NAME OLD_OBJECT_NAME NEW_OBJECT_NAME SQL_TEXT OK
===================== ========================= =============================== =============================== =============================== ================= ======
2 CREATE TABLE T1 <null> <null> 80:0 Y
==============================================================================
SQL_TEXT:
SQL_TEXT:
recreate table t1 (
n1 integer,
n2 integer
)
==============================================================================
3 CREATE TABLE T1 <null> <null> 80:1 N
3 CREATE TABLE T1 <null> <null> 80:1 N
==============================================================================
SQL_TEXT:
SQL_TEXT:
create table t1 (
n1 integer,
n2 integer
)
==============================================================================
4 DROP TABLE T1 <null> <null> 80:2 Y
4 DROP TABLE T1 <null> <null> 80:2 Y
==============================================================================
SQL_TEXT:
SQL_TEXT:
recreate table t1 (
n integer
)
==============================================================================
5 CREATE TABLE T1 <null> <null> 80:3 Y
5 CREATE TABLE T1 <null> <null> 80:3 Y
==============================================================================
SQL_TEXT:
SQL_TEXT:
recreate table t1 (
n integer
)
==============================================================================
6 CREATE DOMAIN DOM1 <null> <null> 80:4 Y
6 CREATE DOMAIN DOM1 <null> <null> 80:4 Y
==============================================================================
SQL_TEXT:
SQL_TEXT:
create domain dom1 as integer
==============================================================================
7 ALTER DOMAIN DOM1 <null> <null> 80:5 Y
7 ALTER DOMAIN DOM1 <null> <null> 80:5 Y
==============================================================================
SQL_TEXT:
SQL_TEXT:
alter domain dom1 type bigint
==============================================================================
8 ALTER DOMAIN DOM1 DOM1 DOM2 80:6 Y
8 ALTER DOMAIN DOM1 DOM1 DOM2 80:6 Y
==============================================================================
SQL_TEXT:
SQL_TEXT:
alter domain dom1 to dom2
==============================================================================

68 changes: 68 additions & 0 deletions doc/sql.extensions/README.name_resolution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Name resolution (FB 6.0)

With the introduction of schemas in Firebird 6.0, the syntax `<name>.<name>` - used for tables, views, procedures,
and functions (both standalone and packaged) - introduces ambiguity when resolving object names using the schema
search path. The ambiguity arises between:

- `<schema>.<object>` (a schema and its object)
- `<package>.<object>` (a package and its object)

This document focuses on name resolution rules for tables, views, procedures, and functions within queries and
code blocks.

## Scope specifier (`%`)

To resolve these ambiguities, Firebird introduces a **scope specifier**, represented by the `%` symbol. This
allows unambiguous referencing of objects.

### Syntax

```sql
<name> % { SCHEMA | PACKAGE } . <name>
```

### Examples

```sql
select *
from plg$profiler%schema.plg$prof_sessions;

execute procedure rdb$profiler%package.pause_session;

call rdb$profiler%package.pause_session();

select rdb$time_zone_util%package.database_version()
from system%schema.rdb$database;

select *
from rdb$time_zone_util%package.transitions('America/Sao_Paulo', timestamp '2017-01-01', timestamp '2019-01-01');
```

## Detailed name resolution rules

Firebird resolves object names following a structured sequence of rules. Once an object is located, the resolution
process halts, ensuring no ambiguity errors occur.

- **`name1.name2.name3`**
1. Look for routine `name3` inside package `name2`, inside schema `name1`.

- **`name1%schema.name2`**
1. Look for object `name2` inside schema `name1`.

- **`name1%package.name2`**
1. Look for object `name2` inside a package `name1` using the schema search path.

- **`name1.name2`**
1. If inside a package named `name1`, look for routine `name2` in the same package.
2. Look in schema `name1` for object `name2`.
3. Look for object `name2` inside a package `name1` using the schema search path.

- **`name`**
1. Look for subroutine `name`.
2. If inside a package, look for routine `name` in the same package.
3. Look for object `name` using the schema search path.

> **_Note:_** Object resolution also depends on the context in which they are used. For example, in
`select * from name1.name2`, `name2` could be a table, view, or procedure. However, in
`execute procedure name1.name2`, `name2` must be a procedure. This distinction means that an `execute procedure`
command versus a `select` command can resolve to different objects.
Loading
Loading