GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(knex): Fix total calculation by CITIZENDOT · Pull Request #3525 · feathersjs/feathers

Conversation

@CITIZENDOT

@CITIZENDOT CITIZENDOT commented Aug 15, 2024

Copy link
Copy Markdown

Summary

  • Tell us about the problem your pull request is solving.
    • When the query contains DISTINCT or GROUP BY, incorrect total is being returned. This PR fixes it by calculating the count using a subquery. More details below:
    • When DISTINCT clause is used, clearSelect() removes the DISTINCT clause in the countBuilder query, hence returning non-distinct count. For eg:
      • SELECT DISTINCT `users.*` FROM `users` WHERE ....
      • is converted to
      • SELECT `*` FROM `users` WHERE ...
      • losing the distinct property of the query.
    • When GROUP BY clause is used, GROUP BY is applied on COUNT(`${name}.${id}`), which is useless, because rows returned by COUNT will not contain any column other than total to GROUP BY. Hence non-distinct rows are returned again.
    • Hence the solution is, to wrap the main query into a subquery, and count the rows returned by it, which is what this PR does.
  • Are there any open issues that are related to this?
    • No. But this is a bug, I can create an issue if necessary.
  • Is this PR dependent on PRs in other repos?
    • No

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@CITIZENDOT
CITIZENDOT marked this pull request as draft August 15, 2024 11:55
@CITIZENDOT
Fix countBuilder
a41ce21
@CITIZENDOT
CITIZENDOT force-pushed the fix-total-calculation branch from 563cab0 to a41ce21 Compare August 15, 2024 12:06
@CITIZENDOT
CITIZENDOT marked this pull request as ready for review August 15, 2024 12:07
@daffl daffl changed the title Fix total calculation fix(knex): Fix total calculation Sep 2, 2024
@daffl

daffl commented Sep 2, 2024

Copy link
Copy Markdown
Member

I think this makes sense, however, the tests are failing with a TypeScript error at https://github.com/feathersjs/feathers/actions/runs/10403476191/job/29583715944?pr=3525#step:8:698

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@CITIZENDOT @daffl
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.