GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fix(sql): count groups for HEAD requests with @group by lnuxe · Pull Request #884 · APIJSON/APIJSON Conversation背景issue #624 反馈: 复现请求(issue 里的原始 JSON): {
"[]": {
"VehicleList_count": {
"vehicleid$": "鄂QD24S8_0%",
"sumdate%": "2023-10-15,2023-10-17",
"@group": "vehicleid,sumdate",
"@column": "vehicleid;sumdate;max(cnt):maxcnt",
"@order": "maxcnt-"
},
"page": 0,
"count": 5
},
"total@": "/[]/total"
}原因
SELECT count(*) AS `count` FROM `sys`.`Vehicle` GROUP BY `vid`,`sdate` 这条 SQL 返回的是每一组的行数(多行),不是分组后的组数,所以 修复在 if (StringUtil.isNotEmpty(getGroup(), true) && RequestMethod.isHeadMethod(getMethod(), true)) { String sql = "SELECT " + (getCache() == JSONMap.CACHE_RAM ? "SQL_NO_CACHE " : "") + column + " FROM " + gainConditionString(tablePath, this); return explain + "SELECT count(*)" + gainAs() + getQuote() + JSONResponse.KEY_COUNT + getQuote() + " FROM (" + sql + ")" + gainAs() + gainSQLAliasWithQuote(); } MySQL / SQL Server 要求 FROM 子查询有别名,用已有的 修复后: -- MySQL SELECT count(*) AS `count` FROM (SELECT count(*) AS `count` FROM `sys`.`Vehicle` GROUP BY `vid`,`sdate`) AS `Vehicle` -- PostgreSQL SELECT count(*) AS "count" FROM (SELECT count(*) AS "count" FROM "sys"."Vehicle" GROUP BY "vid","sdate") AS "Vehicle" 测试新增
双通道验证修复前( 修复后: 全量 fix #624
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsHEAD requests replaced the SELECT with count(*) but kept GROUP BY, so SELECT count(*) AS count FROM Vehicle GROUP BY vid,sdate returned one row per group instead of the number of groups. That made total in grouped pagination report the rows inside a group, as reported in issue 624. Wrap the grouped statement in an outer count(*) subquery, the same way the Oracle branch already does. MySQL and SQL Server require an alias on a FROM subquery, so the subquery is aliased with gainSQLAliasWithQuote(). Tests assert the outer count(*) plus subquery shape for MySQL, PostgreSQL, SQL Server and DB2, and keep the plain count(*) and plain GET paths unchanged. fix APIJSON#624 This branch has not been deployedNo deployments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. 分组后再分页,发现total数量不对,后台sql发现统计的是组内数量,请问有其他查询方法吗?Uh oh!
There was an error while loading. Please reload this page. 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 01402503 — 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. |