Skip to content

Conversation

@andreyaksenov
Copy link
Contributor

@andreyaksenov andreyaksenov commented Sep 12, 2023

@andreyaksenov andreyaksenov force-pushed the sql-constraint-mechanism branch 2 times, most recently from 4018db5 to 2ed6dc5 Compare September 12, 2023 12:13
@andreyaksenov andreyaksenov linked an issue Sep 12, 2023 that may be closed by this pull request
@andreyaksenov andreyaksenov force-pushed the sql-constraint-mechanism branch 3 times, most recently from 80394ee to c300746 Compare September 12, 2023 14:24
@andreyaksenov andreyaksenov linked an issue Sep 12, 2023 that may be closed by this pull request
@andreyaksenov andreyaksenov force-pushed the sql-constraint-mechanism branch 3 times, most recently from 86da5f3 to b4316c3 Compare September 13, 2023 08:50
Copy link

@ImeevMA ImeevMA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thank you for the patch. I have three comments, see them below.

The constraint-name must be an identifier which is valid according to the rules for identifiers.
The constraint-name must be unique within the table.
A constraint name must be an identifier that is valid according to the rules for identifiers.
A constraint name must be unique within the table.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exactly so. There cannot be another table foreign key (= tuple foreign key) constraint with the same name, but it is possible to have a CHECK or UNIQUE table constraint, as well as any column constraint (= field constraint) with the same name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed like this:

A constraint name must be unique within the table for a specific constraint type.
For example, the CHECK and FOREIGN KEY constraints can have the same name.


Only one column in the table may be autoincrement.
However, it is legal to say ``PRIMARY KEY (a, b, c AUTOINCREMENT)`` -- in that case, there
are three columns in the primary key but only the first column (``a``) is AUTOINCREMENT.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this by chance. This is not entirely true. I see that this was added to close #947, but in fact AUTOINCREMENT will be added here to column c.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed to ... but only the third column (``c``) is AUTOINCREMENT.

- A referenced column has a UNIQUE constraint.
- A referenced column has a UNIQUE index.

Note that before the :doc:`2.11.0 </release/2.11.0>` version, uniqueness of a foreign key is checked when creating a constraint (for example, using ``CREATE TABLE`` or ``ALTER TABLE``).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more existence of an index on the referenced columns then uniqueness of a foreign key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to:

Note that before the :doc:`2.11.0 </release/2.11.0>` version, an index existence for the referenced columns is checked when creating a constraint (for example, using ``CREATE TABLE`` or ``ALTER TABLE``).
Starting with 2.11.0, this check is weakened and existence of an index is checked during data insertion.

@andreyaksenov andreyaksenov force-pushed the sql-constraint-mechanism branch from b4316c3 to 6b55382 Compare September 13, 2023 11:36
@xuniq xuniq self-requested a review September 13, 2023 11:54
- Every table must have one and only one primary key.
- Primary-key columns are automatically ``NOT NULL``.
- Primary-key columns are automatically indexed.
- Primary-key columns are unique, that is, it is illegal to have two rows that have the same values for the columns specified in the constraint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Primary-key columns are unique, that is, it is illegal to have two rows that have the same values for the columns specified in the constraint.
- Primary-key columns are unique. That means it is illegal to have two rows with the same values for the columns specified in the constraint.

There is a shorthand: specifying UNIQUE in a :ref:`column definition <sql_column_def_constraint>`.

Unique constraints are similar to primary-key constraints, except that:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Unique constraints are similar to primary-key constraints, except that:
* Unique constraints are similar to primary-key constraints, except that:
a table may have any number of unique keys, and unique keys are not automatically ``NOT NULL``.
* Unique columns are automatically indexed.
* Unique columns are unique. That means it is illegal to have two rows with the same values in the unique-key columns.

Let's make the formatting consistent

- A referenced column has a UNIQUE index.

Note that before the :doc:`2.11.0 </release/2.11.0>` version, an index existence for the referenced columns is checked when creating a constraint (for example, using ``CREATE TABLE`` or ``ALTER TABLE``).
Starting with 2.11.0, this check is weakened and existence of an index is checked during data insertion.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Starting with 2.11.0, this check is weakened and existence of an index is checked during data insertion.
Starting with 2.11.0, this check is weakened and the existence of an index is checked during data insertion.


UNIQUE constraints look like this: |br|
:samp:`UNIQUE ({column-name} [, {column-name}...])`
UNIQUE constraints look like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UNIQUE constraints look like this:
**UNIQUE constraints**
UNIQUE constraints look like this:

I think it's necessary to separate the paragraphs about PRIMARY | UNIQUE | CHECK constraints from each other somehow (with bold?). It's a bit difficult to figure out where a new paragraph starts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, will do

@andreyaksenov andreyaksenov force-pushed the sql-constraint-mechanism branch from 6b55382 to c042ab0 Compare September 13, 2023 13:23
@andreyaksenov andreyaksenov merged commit 5272887 into latest Sep 14, 2023
@andreyaksenov andreyaksenov deleted the sql-constraint-mechanism branch September 14, 2023 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feedback: SQL statements and clauses | Tarantool SQL: changes in using the constraint mechanism

4 participants