mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-09-15 21:02:35 +00:00
fix(websocketspec,mqttspec,resolvemcp): stop casting citext columns to TEXT for LIKE/ILIKE
Same class of bug as the restheadspec/resolvespec fix: these handlers unconditionally rendered CAST(col AS TEXT) LIKE/ILIKE for every column, which flips a citext column to case-sensitive matching and defeats a citext index. Thread the model through to buildFilterCondition/applyFilters so reflection.IsCitextColumn can skip the cast for citext columns. resolvemcp's eq/neq/gt/lt paths never cast (they never had the restheadspec-style reflect.Kind cast heuristic), so this only touches LIKE/ILIKE. funcspec is unaffected: it has no Go struct model to check against (colname/value come straight from SQL function parameters).
This commit is contained in:
+14
-2
@@ -720,7 +720,13 @@ func (h *Handler) readMultiple(hookCtx *HookContext) (data interface{}, metadata
|
||||
}
|
||||
op := strings.ToLower(filter.Operator)
|
||||
if op == "like" || op == "ilike" {
|
||||
query = query.Where(fmt.Sprintf("CAST(%s AS TEXT) %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
// citext columns are already case-insensitive; casting to TEXT would
|
||||
// switch to case-sensitive matching and defeat a citext index.
|
||||
if reflection.IsCitextColumn(hookCtx.Model, filter.Column) {
|
||||
query = query.Where(fmt.Sprintf("%s %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
} else {
|
||||
query = query.Where(fmt.Sprintf("CAST(%s AS TEXT) %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
}
|
||||
} else {
|
||||
query = query.Where(fmt.Sprintf("%s %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
}
|
||||
@@ -786,7 +792,13 @@ func (h *Handler) readMultiple(hookCtx *HookContext) (data interface{}, metadata
|
||||
}
|
||||
op := strings.ToLower(filter.Operator)
|
||||
if op == "like" || op == "ilike" {
|
||||
countQuery = countQuery.Where(fmt.Sprintf("CAST(%s AS TEXT) %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
// citext columns are already case-insensitive; casting to TEXT would
|
||||
// switch to case-sensitive matching and defeat a citext index.
|
||||
if reflection.IsCitextColumn(hookCtx.Model, filter.Column) {
|
||||
countQuery = countQuery.Where(fmt.Sprintf("%s %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
} else {
|
||||
countQuery = countQuery.Where(fmt.Sprintf("CAST(%s AS TEXT) %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
}
|
||||
} else {
|
||||
countQuery = countQuery.Where(fmt.Sprintf("%s %s ?", filter.Column, h.getOperatorSQL(filter.Operator)), filter.Value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user