Skip to content

Commit

Permalink
Merge #128540
Browse files Browse the repository at this point in the history
128540: sql: support creating and dropping triggers r=DrewKimball a=DrewKimball

#### sql: add trigger descriptor

This commit adds a `Triggers` field to the table descriptor, which is
a list of `TriggerDescriptor` structs. `TriggerDescriptor` contains all
the information needed to build and execute a trigger, including the
timing, matched event type, and fully-resolved trigger function body.
This commit also adds the logic needed to track and update object
references and back-references within descriptors due to triggers.

Informs #126359

Release note: None

#### schemachanger: support CREATE TRIGGER in the declarative schema changer

This commit adds support for `CREATE TRIGGER` statements to the declarative
schema changer. The implementation assumes that most of the validation will
be carried out during planning, apart from checking for cross-database
references. Note that `CREATE TRIGGER` will not be implemented in the
legacy schema changer.

Informs #126359

Release note: None

#### schemachanger: support DROP TRIGGER in the declarative schema changer

This commit adds `DROP TRIGGER` support to the declarative schema changer.
Just as with `CREATE TRIGGER`, `DROP TRIGGER` will not be implemented in
the legacy schema changer.

Informs #126359

Release note (sql change): Implemented DROP TRIGGER statements. Note that
the CASCADE option for dropping a trigger is not supported.

#### opt: add support for CREATE TRIGGER in optimizer

This commit finalizes support for `CREATE TRIGGER` by adding support
for it in the optimizer. This includes validation for the statement,
dependency resolution, and logic tests.

Fixes #126359

Release note (sql change): Added support for CREATE TRIGGER. Note that
OR REPLACE syntax is not yet supported.

Co-authored-by: Drew Kimball <[email protected]>
  • Loading branch information
craig[bot] and DrewKimball committed Oct 12, 2024
2 parents 29a73fa + 0b647ac commit 30dbb17
Show file tree
Hide file tree
Showing 130 changed files with 5,782 additions and 436 deletions.
50 changes: 49 additions & 1 deletion docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,30 @@ An event of type `create_table` is recorded when a table is created.
| `Owner` | The name of the owner for the new table. | yes |


#### Common fields

| Field | Description | Sensitive |
|--|--|--|
| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | no |
| `EventType` | The type of the event. | no |
| `Statement` | A normalized copy of the SQL statement that triggered the event. The statement string contains a mix of sensitive and non-sensitive details (it is redactable). | partially |
| `Tag` | The statement tag. This is separate from the statement string, since the statement string can contain sensitive information. The tag is guaranteed not to. | no |
| `User` | The user account that triggered the event. The special usernames `root` and `node` are not considered sensitive. | depends |
| `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | no |
| `ApplicationName` | The application name for the session where the event was emitted. This is included in the event to ease filtering of logging output by application. | no |
| `PlaceholderValues` | The mapping of SQL placeholders to their values, for prepared statements. | yes |

### `create_trigger`

An event of type `create_trigger` is recorded when a trigger is created.


| Field | Description | Sensitive |
|--|--|--|
| `TableName` | Name of the trigger's table. | yes |
| `TriggerName` | Name of the created trigger. | yes |


#### Common fields

| Field | Description | Sensitive |
Expand Down Expand Up @@ -1473,7 +1497,7 @@ An event of type `drop_function` is recorded when a user-defined function is dro

| Field | Description | Sensitive |
|--|--|--|
| `FunctionName` | Name of the created function. | yes |
| `FunctionName` | Name of the dropped function. | yes |


#### Common fields
Expand Down Expand Up @@ -1572,6 +1596,30 @@ An event of type `drop_table` is recorded when a table is dropped.
| `CascadeDroppedViews` | The names of the views dropped as a result of a cascade operation. | yes |


#### Common fields

| Field | Description | Sensitive |
|--|--|--|
| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | no |
| `EventType` | The type of the event. | no |
| `Statement` | A normalized copy of the SQL statement that triggered the event. The statement string contains a mix of sensitive and non-sensitive details (it is redactable). | partially |
| `Tag` | The statement tag. This is separate from the statement string, since the statement string can contain sensitive information. The tag is guaranteed not to. | no |
| `User` | The user account that triggered the event. The special usernames `root` and `node` are not considered sensitive. | depends |
| `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | no |
| `ApplicationName` | The application name for the session where the event was emitted. This is included in the event to ease filtering of logging output by application. | no |
| `PlaceholderValues` | The mapping of SQL placeholders to their values, for prepared statements. | yes |

### `drop_trigger`

An event of type `drop_trigger` is recorded when a trigger is dropped.


| Field | Description | Sensitive |
|--|--|--|
| `TableName` | Name of the trigger's table. | yes |
| `TriggerName` | Name of the dropped trigger. | yes |


#### Common fields

| Field | Description | Sensitive |
Expand Down
1 change: 0 additions & 1 deletion docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,6 @@ trigger_event ::=
| 'UPDATE'
| 'UPDATE' 'OF' name_list
| 'TRUNCATE'
| 'UPSERT'

trigger_transition_list ::=
( trigger_transition ) ( ( trigger_transition ) )*
Expand Down
Loading

0 comments on commit 30dbb17

Please sign in to comment.