contributte / contributte/datagrid

Incorrect rows count when using GROUP BY with multiple columns - Nette\Database\Table

Open
#991 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T: Bug
Dominant language
PHP
Stars
296
Forks
215
PR merge metrics
No merged PRs in 30d

Description

Hi,
I found the bug in Nette\Database\Table data source when using GROUP BY with multiple columns.

Here is example of SQL queries.
Query for the datagrid with 703 total rows.

SELECT `id`, `title`, `variant`, CONCAT_WS(" - ", `title`, `variant`, `course_city`, `course_date`) AS `full_name` 
FROM `orders_products` 
GROUP BY `title`, `variant`, `course_city`, `course_date`;

Datagrid generated this SQL query from the getCount() function which gets 0 rows.

SELECT COUNT(DISTINCT `title`, `variant`, `course_city`, `course_date`) 
FROM `orders_products`;

I think right SQL query with multiple GROUP BY columns should be:

SELECT COUNT(*) 
FROM (
SELECT COUNT(id) 
FROM `orders_products`
GROUP BY `title`, `variant`, `course_city`, `course_date`
) AS x;

Best regards

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Nette\Database\Table's getCount() behavior and reproduce the reported datagrid query with GROUP BY on title, variant, course_city, and course_date. Compare the generated COUNT(DISTINCT ...) result with the grouped query's 703 rows; done means the count is correct for multiple GROUP BY columns.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.