entc/gen: reduce the usage of DISTINCT in queries (#3305)

Most queries are not graph traversals but rather regular table scans,
in which case the DISTINCT clause is not needed as duplicates cannot be
returned (unless query was modified by the user).
This commit is contained in:
Ariel Mashraki
2023-02-06 22:40:50 +02:00
committed by GitHub
parent 138bd2bc1d
commit 939c7cff1a
125 changed files with 508 additions and 1474 deletions

View File

@@ -375,20 +375,12 @@ func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
}
func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
_spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
Table: user.Table,
Columns: user.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
},
From: uq.sql,
Unique: true,
}
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
_spec.From = uq.sql
if unique := uq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if uq.path != nil {
_spec.Unique = true
}
if fields := uq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))