neetkee
01/12/2024, 11:43 AMTable
.selectAll()
.where { Table.someColumn.eq(someValue) }
.count()
Table
.select(Table.id)
.where { Table.someColumn.eq(someValue) }
.count()
Both will produce the same query with COUNT(*). So, .selectAll, .select in this case are required, but redundant. I know it's possible to do .select(Table.id.count()), but adding .count at the end of the statement is just easier.Manas Marthi
01/12/2024, 11:45 AMselect count(*)
, and not select count(id)
Manas Marthi
01/12/2024, 11:45 AMselect count(*)
performs poorly , and use select count(1)
or select count(id)
insteadManas Marthi
01/12/2024, 11:47 AMneetkee
01/12/2024, 11:51 AM.select, .selectAll
have no effect, but are still required.
In terms of performance, in these simple cases, I don't think there any difference between count(*)
and count(1)
Manas Marthi
01/12/2024, 12:31 PMneetkee
01/12/2024, 12:38 PMExposed
logger should be enoughChantal Loncle
01/12/2024, 3:55 PMcount()
itself hasn't changed in that Table.selectAll()
and Table.select(Table.id)
do produce the same sql SELECT COUNT(*) ...
, much in the same way that using slice()
with the old DSL provided the same redundancy by generating the same sql:
Table
.select { Table.someColumn eq someValue }
.count()
Table
.slice(Table.id)
.select { Table.someColumn eq someValue }
.count()
The difference does lie in that select()
and selectAll()
are required because they have an important purpose as the only starting points for the instantiation of a Query
.
This restriction complies with the start of standard SELECT
syntax and removes the ambiguity of the old select { }
, i.e. SELECT what? ... where? ..., by making the intent of each step explicitly readable.
Their effect is to allow query builder functions to be chained to the same instance.
Given the placement of COUNT
in the syntax, it would be nice to do something like:
Table
.selectCountAll()
.where { Table.someColumn eq someValue }
But this is currently not feasible due to the reliance on count()
being a terminal operation in a query builder.
Ideally, would you prefer to see an alternative that uses a dual-purpose function, instead of having to chain an instantiator with a builder function? Something like:
// before
Table
.selectAll()
.where { Table.someColumn eq someValue }
.count()
// after
Table
.selectAllWhere { Table.someColumn eq someValue }
.count()
If so, please don't hesitate to open a feature request on YouTrack so other users can upvote.Luis Arcos
01/13/2024, 10:27 AMselectCountAll
idea. I always found that placing count()
at the end of the statement to be weird considering it is part of the Select clause is SQL syntax.neetkee
01/16/2024, 5:08 AM.count()
at the end looks odd, but it's easier to use than .select(Table.id.count())
. I think .selectCountAll()
would solve this problem.