I create a logical table named message, and use two underlying sharding tables: message_01 and message_02.
When using go-gorm/sharding plugin alone, everything works well, as in test case TestSharding.
However, after I added Clauses(hints.ForceIndex("idx_content")) in the query, the sharding plugin would fail, as in test case TestShardingAndForceIndex.
The error log shows Error 1146 (42S02): Table 'gorm.message' doesn't exist.
After some digging up, I found the cause of the issue comes from this line: https://github.com/go-gorm/sharding/blob/1ccc1749c6a4c2f77b23ddd515bf7c33dd6e350b/sharding.go#L307
It seems sqlparser can't handle the FORCE INDEX syntax in SQL, causing the sharding plugin fails and falls back to original(not sharded) SQL.
A relevant issue: https://github.com/go-gorm/sharding/issues/91
GORM Playground Link
https://github.com/go-gorm/playground/pull/726
Description
I create a logical table named
message
, and use two underlying sharding tables:message_01
andmessage_02
. When using go-gorm/sharding plugin alone, everything works well, as in test caseTestSharding
. However, after I added Clauses(hints.ForceIndex("idx_content")) in the query, the sharding plugin would fail, as in test caseTestShardingAndForceIndex
. The error log showsError 1146 (42S02): Table 'gorm.message' doesn't exist
. After some digging up, I found the cause of the issue comes from this line: https://github.com/go-gorm/sharding/blob/1ccc1749c6a4c2f77b23ddd515bf7c33dd6e350b/sharding.go#L307 It seemssqlparser
can't handle theFORCE INDEX
syntax in SQL, causing the sharding plugin fails and falls back to original(not sharded) SQL. A relevant issue: https://github.com/go-gorm/sharding/issues/91