Skip to content

Commit

Permalink
Merge pull request #2250 from dolthub/gitbook-dev
Browse files Browse the repository at this point in the history
publish doltgres
  • Loading branch information
tbantle22 authored Jun 4, 2024
2 parents 1d27328 + f4ded62 commit c511280
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 198 deletions.
8 changes: 4 additions & 4 deletions packages/doltgres/content/concepts/git/working-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ the staging set. The staging set is committed by issuing a `dolt_commit()` comma
appropriate metadata.

If you start a Doltgres SQL server and start making changes, you are making changes to the working
set. If you never make a commit, your working set is a standard MySQL database. So, a way to think
about your working set is Doltgres without version control features, just a standard MySQL
set. If you never make a commit, your working set is a standard Postgres database. So, a way to think
about your working set is Doltgres without version control features, just a standard Postgres
relational database.

## How to use Working Sets
Expand All @@ -24,7 +24,7 @@ to a working set, you can `dolt_reset()` or `dolt_checkout()` to the previous co

## Difference between Git Working Sets and Doltgres Working Sets

Git working sets change files. Doltgres working sets change tables.
Git working sets change files. Doltgres working sets change tables.

On the command line, working set changes do follow to the newly checked out branch, just like
Git. However, in SQL server mode, working set changes are not transferred to the newly checked out
Expand Down Expand Up @@ -91,7 +91,7 @@ call dolt_checkout('branch2');
+--------+
| 0 |
+--------+
mysql> select * from docs ;
select * from docs ;
+----+----+
| pk | c1 |
+----+----+
Expand Down
26 changes: 13 additions & 13 deletions packages/doltgres/content/concepts/sql/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ title: Constraints

## What is a Constraint?

Constraints restrict the values allowed in a column. There are multiple forms of constraints:
Constraints restrict the values allowed in a column. There are multiple forms of constraints:

1. `NOT NULL` or `UNIQUE` in the column definition
2. Check constraints
3. Foreign Key constraints

Simple constraints like `NOT NULL` and `UNIQUE` can be added when defining a column. These constrain the column to not be NULL and only contain unique values, respectively.

Check constraints allow the database user to define more complex constraints, like ranges on numerical values.
Check constraints allow the database user to define more complex constraints, like ranges on numerical values.

Foreign key constraints allow you to reference and define relations between other tables in your database.
Foreign key constraints allow you to reference and define relations between other tables in your database.

## How to use Constraints

Expand All @@ -26,9 +26,9 @@ database.

You can add constraints when running `CREATE TABLE` statements or add them to existing tables using `ALTER` statements.

## Difference between MySQL Constraints and Doltgres Constraints
## Difference between Postgres Constraints and Doltgres Constraints

MySQL and Doltgres constraints are functionally equivalent.
Postgres and Doltgres constraints are functionally equivalent.

## Interaction with Doltgres Version Control

Expand All @@ -49,15 +49,15 @@ making a Doltgres commit.

```sql
create table employees (
id int,
last_name varchar(100),
first_name varchar(100),
age int,
primary key(id),
id int,
last_name varchar(100),
first_name varchar(100),
age int,
primary key(id),
constraint over_18 check (age >= 18));
create table pay (id int,
salary int,
primary key(id),
create table pay (id int,
salary int,
primary key(id),
foreign key (id) references employees(id));
```

Expand Down
2 changes: 1 addition & 1 deletion packages/doltgres/content/concepts/sql/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ When you connect a client to a running server, you can see the databases being s
command in the `psql` shell. To use a specific database, you issue a `\c <database>` statement. You
can also specify the database in the connection string to connect to a particular database.

## Difference between MySQL Databases and Doltgres Databases
## Difference between Postgres Databases and Doltgres Databases

In Doltgres, databases act like they do in Postgres.

Expand Down
5 changes: 3 additions & 2 deletions packages/doltgres/content/concepts/sql/indexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ performance. Additionally, you should have the disk space available to store the

You create indexes using the `CREATE INDEX` SQL statement.

## Difference between MySQL Secondary Indexes and Doltgres Secondary Indexes
## Difference between Postgres Secondary Indexes and Doltgres Secondary Indexes

Functionally, Doltgres and MySQL indexes are equivalent.
Functionally, Doltgres and Postgres indexes are equivalent.

## Interaction with Doltgres Version Control

Expand All @@ -37,6 +37,7 @@ Doltgres will merge indexes as part of a Doltgres merge. This can be used to off
to a branch or offline clone.

## Example

```
create index index1 on complex(c1);
```
4 changes: 2 additions & 2 deletions packages/doltgres/content/concepts/sql/primary-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ key is a unique identification or id number.

In most databases, a map of primary keys to the values of the other columns in the table is how the
data is laid out on disk or memory. This makes row lookups by primary key indexed lookups. Indexed
lookups can be accomplished in constant time (ie. O(1)). Thus, use of primary keys in table
lookups can be accomplished in constant time (ie. O(1)). Thus, use of primary keys in table
definition and queries is a common database performance optimization. [Secondary
Indexes](./indexes.md) are called "secondary" to distinguish them from primary keys.

Expand All @@ -30,7 +30,7 @@ database applications assign a primary key, usually called `id`, on row creation

<!-- TODO: talk about sequences in primary keys -->

## Difference between MySQL Primary Keys and Doltgres Primary Keys
## Difference between Postgres Primary Keys and Doltgres Primary Keys

Postgres and Doltgres primary keys are functionally the same. You use the same syntax to define and
alter them.
Expand Down
4 changes: 2 additions & 2 deletions packages/doltgres/content/concepts/sql/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Schema

## What is a Schema?

Schema defines the shape of the data in your database.
Schema defines the shape of the data in your database.

<!-- TODO: talk about database schemas -->

Expand Down Expand Up @@ -40,7 +40,7 @@ Changing schema can be a costly operation. For instance, adding an index to a co
database requires scanning the entire table and writing a new index artifact, usually while also
restricting writes to that table.

## Difference between MySQL Schema and Doltgres Schema
## Difference between Postgres Schema and Doltgres Schema

Doltgres supports [most Postgres schema elements at least
partially](../../reference/sql-support/supported-types.md), with more support being built out
Expand Down
2 changes: 1 addition & 1 deletion packages/doltgres/content/concepts/sql/system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ support should have the same lifecycle behavior as Postgres.
We also have Doltgres-specific system variables, which can be found
[here](../../reference/sql/version-control/dolt-sysvars.md). Most dolt specific variables are
prefixed with either `dolt_...` or the database's name (ex: `mydb_...`). These can be listed in the
MySQL shell with show queries: `show all`.
Postgres shell with show queries: `show all`.

## Interaction with Doltgres Version Control

Expand Down
2 changes: 1 addition & 1 deletion packages/doltgres/content/concepts/sql/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A Postgres and Dolt table function the same on the surface. `CREATE` and `ALTER`
same on both.

Dolt and Postgres are [row major](https://en.wikipedia.org/wiki/Row-_and_column-major_order),
meaning row values are stored next to each other. However, MySQL stores data in a binary tree
meaning row values are stored next to each other. However, Postgres stores data in a binary tree
structure while Dolt stores table data on disk using a content-addressed binary tree called a
[prolly tree](https://docs.dolthub.com/architecture/storage-engine/prolly-tree). This setup makes Dolt [fairly
comparable in query performance to Postgres](../../reference/benchmarks/latency.md) while also
Expand Down
14 changes: 7 additions & 7 deletions packages/doltgres/content/concepts/sql/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Transactions

## What is a Transaction?

A transaction is the unit of change isolation is a database.
A transaction is the unit of change isolation is a database.

## How to use Transactions

Expand All @@ -21,17 +21,17 @@ back to the way it was when the transaction began.
Postgres and Doltgres both automatically commit every statement that wasn't explicitly placed in a
transaction with a `BEGIN` statement.

## Difference between MySQL Transaction and Doltgres Transaction
## Difference between Postgres Transaction and Doltgres Transaction

Doltgres uses the Read Committed transaction model whereas Postgres supports [all transaction
isolation levels](https://www.postgresql.org/docs/current/transaction-iso.html).

## Interaction with Doltgres Version Control

Traditional SQL transactions exist in isolation from Doltgres version control features.
Traditional SQL transactions exist in isolation from Doltgres version control features.

Doltgres can be thought of having two layers of transactions. The first layer accessed with `BEGIN`
and `COMMIT` SQL statements is the same as MySQL. Doltgres adds an additional second layer with
and `COMMIT` SQL statements is the same as Postgres. Doltgres adds an additional second layer with
branches and Doltgres commits. Branches can be thought of as long running transactions that may or
may not be merged.

Expand All @@ -41,7 +41,7 @@ variable](./system-variables.md),

## Example

```
```sql
BEGIN;
select * from docs;
+----+----+
Expand All @@ -63,8 +63,8 @@ select * from docs;
| 2 | 2 |
| 3 | 0 |
+----+----+
mysql> rollback;
mysql> select * from docs;
database=# rollback;
database=# select * from docs;
+----+----+
| pk | c1 |
+----+----+
Expand Down
2 changes: 1 addition & 1 deletion packages/doltgres/content/concepts/sql/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type of a column with `ALTER` statements.
When querying tables, the type of the column defines which functions can be used on the data
retrieved. To manipulate the type of a column when querying you use the `CONVERT()` function.

## Difference between MySQL Types and Doltgres Types
## Difference between Postgres Types and Doltgres Types

Doltgres supports [most Postgres types](../../reference/sql-support/supported-types.md), with more
being implemented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ title: Branch Permissions
## What are Branch Permissions?

Branch permissions are a way of managing how users may interact with branches when running Doltgres
as a server (via `doltgres sql-server`). The branch permissions model is composed of two system
tables: `dolt_branch_control` and `dolt_branch_namespace_control`. The former table handles branch
modification, while the latter table handles branch creation. All operations that are not
as a server (via `doltgres sql-server`). The branch permissions model is composed of two system
tables: `dolt_branch_control` and `dolt_branch_namespace_control`. The former table handles branch
modification, while the latter table handles branch creation. All operations that are not
explicitly done as a client connected to a server (such as locally using the CLI) will bypass branch
permissions.

Expand All @@ -21,7 +21,7 @@ Each column is composed of a string that represents a pattern-matching expressio
### `dolt_branch_control`

| Column | Type | Collation |
|:------------|:------------------------------|:-------------------|
| :---------- | :---------------------------- | :----------------- |
| database | VARCHAR(16383) | utf8mb4_0900_ai_ci |
| branch | VARCHAR(16383) | utf8mb4_0900_ai_ci |
| user | VARCHAR(16383) | utf8mb4_0900_bin |
Expand All @@ -31,7 +31,7 @@ Each column is composed of a string that represents a pattern-matching expressio
### `dolt_branch_namespace_control`

| Column | Type | Collation |
|:---------|:---------------|:-------------------|
| :------- | :------------- | :----------------- |
| database | VARCHAR(16383) | utf8mb4_0900_ai_ci |
| branch | VARCHAR(16383) | utf8mb4_0900_ai_ci |
| user | VARCHAR(16383) | utf8mb4_0900_bin |
Expand All @@ -40,7 +40,7 @@ Each column is composed of a string that represents a pattern-matching expressio
### Available Permissions

| Permission | Effect |
|:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| admin | Grants all permissions available. In addition, grants write access to entries on both system tables, as long as the database and branch are equivalent, or they're subset of the database + branch that this permission belongs to. |
| write | Grants the ability to write on the branch, as well as modify the branch in all possible ways (rename, delete, etc.). |
| read | Does not explicitly grant any permissions, as having the ability to read a branch is an irrevocable right for all users. This is just for the visual convenience, versus having an empty field. |
Expand All @@ -54,8 +54,8 @@ The form of pattern matching that each column implements is very similar to how
Most characters are interpreted as-is, with the exception of three characters.

| Character | Function |
|:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| _ | Matches a single character, regardless of what that character is. |
| :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| \_ | Matches a single character, regardless of what that character is. |
| % | Matches zero or more characters, regardless of what those characters are. |
| \ | Escapes the next character, allowing it to be compared literally. This is only useful when attempting to match one of these special characters, as it is otherwise ignored (has no effect). |

Expand Down Expand Up @@ -93,7 +93,7 @@ The modification of both system tables are controlled by two entities: the privi
Any user that satisfies the privilege requirements may edit the appropriate entries in both system tables.

| Scope | Privileges | Remarks |
|:-------------|:-------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------|
| :----------- | :----------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `*.*` | SUPER, GRANT OPTION | Considered a global admin. May edit any entry in either table, including entries containing special characters. |
| `*.*` | CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, EXECUTE, GRANT OPTION | Same as above. |
| `database.*` | CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, EXECUTE, GRANT OPTION | Considered a database admin. May edit entries only for their specific database. This also excludes all databases that contain _any_ special characters. |
Expand Down Expand Up @@ -152,9 +152,11 @@ It is worth noting that operations such as renaming a branch also require the co
This is because a rename may be viewed as a copy and delete, therefore it is modifying the original branch.

To turn `dolt_branch_namespace_control` into a blacklist (just like `dolt_branch_control`), then run the following statement:

```sql
INSERT INTO dolt_branch_namespace_control VALUES ('%', '%', '', '');
```

This will add an entry that will match every possible branch, but will never match a user as a user will never have an empty user and host.
Due to the longest match rule, this entry will be ignored when a valid match is found.

Expand All @@ -175,8 +177,8 @@ The following examples are a small snippet that shows branch permissions in acti
It is assumed that this document has been read in full, as concepts that are explained in previous sections are not explained in-depth.
The [setup section](#setup) is run before each example, therefore remember to have a dedicated terminal window for [setup](#setup) if you want to try any of these examples yourself.
All examples other than [setup](#setup) will exclusively use the second terminal window.
All examples will use MySQL's default client, `mysql`.
Feel free to use your desired MySQL client.
All examples will use Postgres' default client, `psql`.
Feel free to use your desired Postgres client.

### Setup

Expand Down Expand Up @@ -254,14 +256,15 @@ INSERT INTO dolt_branch_namespace_control VALUES ('example', '_main', 'anotherus
```

### Restricting Branch Names
Please refer to the [setup section](#setup) before continuing this example. This example shows how
to [restrict which users are able to use branch names](#branch-creation) with the `main` prefix. To

Please refer to the [setup section](#setup) before continuing this example. This example shows how
to [restrict which users are able to use branch names](#branch-creation) with the `main` prefix. To
do this, we insert a `main%` entry into the `dolt_branch_namespace_control` table, assigning the
`testuser` user. We create another entry with `mainroot%` as the branch name, and assign that to
`root`. This means that `root` is able to create any branches with names that **do not** start with
`main`, but is unable to create branches that **do** start with `main`. The exception being
`testuser` user. We create another entry with `mainroot%` as the branch name, and assign that to
`root`. This means that `root` is able to create any branches with names that **do not** start with
`main`, but is unable to create branches that **do** start with `main`. The exception being
`mainroot`, which while having `main` as a prefix, it is considered [the longest
match](#longest-match), and therefore takes precedence over the `main%` entry. Consequently,
match](#longest-match), and therefore takes precedence over the `main%` entry. Consequently,
`testuser` cannot use `mainroot` as a prefix, as [the longest match](#longest-match) overrides their
`main%` entry.

Expand All @@ -286,7 +289,7 @@ CALL DOLT_BRANCH('mainroot');
+--------+
1 row in set (0.00 sec)

mysql> exit;
example=# exit;

$ psql --user=testuser
CALL DOLT_BRANCH('main1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Replication
# Replication

Doltgres can [replicate data](../../../concepts/rdbms/replication.md) between two or more
Doltgres servers, or can be a read-replica for a MySQL server. This page describes the two supported
Doltgres servers, or can be a read-replica for a Postgres server. This page describes the two supported
replication modes between a Doltgres primary server and Doltgres replica servers. See the [Postgres
to Doltgres Replication guide](../../../guides/replication-from-postgres.md) for more information on
setting up a Doltgres server as a read-replica for a Postgres server.
Expand Down
Loading

0 comments on commit c511280

Please sign in to comment.