Skip to content

Commit

Permalink
Merge pull request #727 from GuptaManan100/ordering-varchar
Browse files Browse the repository at this point in the history
Updated documentation after supporting ordering for varchar columns
  • Loading branch information
harshit-gangal authored Mar 26, 2021
2 parents d98dda7 + e179630 commit 6da3f2e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Vitess supports MySQL DDL, and will send `ALTER TABLE` statements to each of the

Vitess supports `INNER JOIN` including cross-shard joins. `LEFT JOIN` is supported as long as there are not expressions that compare columns on the outer table to the inner table in sharded keyspaces.

### Ordering

Vitess supports the ordering for all the columns irrespective of the data type. However it further requests collation specific information (`weight_string`) from the underlying MySQL instance. This can be avoided for numeric columns which is discussed further in [Advanced VSchema Properties](../../../user-guides/vschema-guide/advanced-vschema/#column-list)

### Aggregation

Vitess supports a subset of `GROUP BY` operations, including cross-shard operations. The VTGate servers are capable of scatter-gather operations, but can only stream results. Thus, a query that performs a `GROUP BY colx ORDER BY coly` may be refused if the intermediate result set is larger than VTGate's in-memory limit.
Expand Down
65 changes: 44 additions & 21 deletions content/en/docs/user-guides/vschema-guide/advanced-vschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,29 @@ It may become a challenge to keep a reference table correctly updated across all

The VSchema allows you to specify the list of columns along with their types for every table. This allows Vitess to make optimization decisions where necessary.

For example, specifying that a column contains text allows VTGate to request further collation specific information (`weight_string`) if additional sorting is needed after collecting results from all shards.
For example, specifying that a column contains numeric data allows VTGate to not request further collation specific information (`weight_string`) if additional sorting is needed after collecting results from all shards.

For example, issuing this query against `customer` would fail:
For example, issuing this query against `customer` would add the `weight_string` column while sending the query to the vttablets:

```text
mysql> select customer_id, uname from customer order by uname;
ERROR 1105 (HY000): vtgate: http://sougou-lap1:12345/: types are not comparable: VARCHAR vs VARCHAR
```json
Query - select integer_col from customer order by integer_col;
Plan -
{
"QueryType": "SELECT",
"Original": "select integer_col from customer order by integer_col",
"Instructions": {
"OperatorType": "Route",
"Variant": "SelectScatter",
"Keyspace": {
"Name": "customer",
"Sharded": true
},
"FieldQuery": "select integer_col, weight_string(integer_col) from `customer` where 1 != 1",
"OrderBy": "0 ASC",
"Query": "select integer_col, weight_string(integer_col) from `customer` order by integer_col asc",
"Table": "`customer`"
}
}
```

However, we can modify the VSchema as follows:
Expand All @@ -73,26 +89,33 @@ However, we can modify the VSchema as follows:
"sequence": "product.customer_seq"
},
"columns": [{
"name": "uname",
"type": "VARCHAR"
"name": "integer_col",
"type": "INT16"
}]
}
```

Re-issuing the same query will now succeed:

```text
mysql> select customer_id, uname from customer order by uname;
+-------------+---------+
| customer_id | uname |
+-------------+---------+
| 1 | alice |
| 2 | bob |
| 3 | charlie |
| 4 | dan |
| 5 | eve |
+-------------+---------+
5 rows in set (0.00 sec)
Re-issuing the same query will now not use `weight_string`:

```json
Query - select integer_col from customer order by integer_col;
Plan -
{
"QueryType": "SELECT",
"Original": "select integer_col from customer order by integer_col",
"Instructions": {
"OperatorType": "Route",
"Variant": "SelectScatter",
"Keyspace": {
"Name": "customer",
"Sharded": true
},
"FieldQuery": "select integer_col from `customer` where 1 != 1",
"OrderBy": "0 ASC",
"Query": "select integer_col from `customer` order by integer_col asc",
"Table": "`customer`"
}
}
```

Specifying columns against tables also allows VTGate to resolve ambiguous naming of columns against the right tables.
Expand Down

0 comments on commit 6da3f2e

Please sign in to comment.