From adfa1497da645cc8e8605151aff2af1da6effe55 Mon Sep 17 00:00:00 2001 From: marvin Date: Wed, 19 Jan 2022 10:54:59 +0800 Subject: [PATCH] fix small mistake in diagram --- docs/query.md | 8 ++++---- docs/query.svg | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/query.md b/docs/query.md index d463e69..b3eab5f 100644 --- a/docs/query.md +++ b/docs/query.md @@ -54,16 +54,16 @@ end subgraph database [Database] - posts_other[("orders_0, orders_1 ... orders_3")] - posts_4[(orders_4)] - posts_last[("orders_5 ... orders_15")] + orders_other[("orders_0, orders_1 ... orders_3")] + orders_4[(orders_4)] + orders_last[("orders_5 ... orders_15")] other_tables[(Other non-sharding tables
users, stocks, topics ...)] new_sql-->| Sharding Query | orders_4 check_table_1-.->| None sharding Query |other_tables end -posts_4-->result +orders_4-->result other_tables-.->result result[/Query results\] ``` diff --git a/docs/query.svg b/docs/query.svg index cb056db..9908005 100644 --- a/docs/query.svg +++ b/docs/query.svg @@ -1,10 +1,10 @@ -
Database
MyConnPool
database/sql - Conn
Gorm
Gorm Query
Exist
Not exist
Not match ShardingKey
Match ShardingKey
Get table name
Replace TableName to get new SQL
Sharding Query
None sharding Query
orders_0, orders_1 ... orders_3
orders_4
orders_5 ... orders_15
Other non-sharding tables
users, stocks, topics ...
orders_4
Check sharding rules
by table name
Parser SQL to get AST
+
Database
MyConnPool
database/sql - Conn
Gorm
Gorm Query
Exist
Not exist
Not match ShardingKey
Match ShardingKey
Get table name
Replace TableName to get new SQL
Sharding Query
None sharding Query
orders_0, orders_1 ... orders_3
orders_4
orders_5 ... orders_15
Other non-sharding tables
users, stocks, topics ...
Check sharding rules
by table name
Parser SQL to get AST

- ast = sqlparser.Parse(sql)
Format sql, args for get full SQL

+ ast = sqlparser.Parse(sql)
Format sql, args for get full SQL

sql = select * from orders
where user_id = 100 and status = 1
- limit 10 order by id desc
router(sql, args)

Sharding rules
Return Raw SQL
Return Error
SQL query must has sharding key
Use value in WhereValue (100) for get sharding table index
orders + (100 % 16)
Sharding Table = orders_4
select * from orders_4
where user_id = 100 and status = 1
limit 10 order by id desc
match_sharding_key
ExecContext
QueryContext
QueryRowContext
Conn
connPool.QueryContext(sql, args)
Gorm DB
SQL Query

+ limit 10 order by id desc
router(sql, args)

Sharding rules
Return Raw SQL
Return Error
SQL query must has sharding key
Use value in WhereValue (100) for get sharding table index
orders + (100 % 16)
Sharding Table = orders_4
select * from orders_4
where user_id = 100 and status = 1
limit 10 order by id desc
match_sharding_key
ExecContext
QueryContext
QueryRowContext
Conn
connPool.QueryContext(sql, args)
Gorm DB
SQL Query

select * from orders
where user_id = ? and status = ?
limit 10 order by id desc
-args = [100, 1]
Query results
\ No newline at end of file +args = [100, 1]
Query results
\ No newline at end of file