Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Additional query optimization for #502 #506

Closed
coverrt opened this issue Aug 22, 2022 · 1 comment
Closed

[Suggestion] Additional query optimization for #502 #506

coverrt opened this issue Aug 22, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@coverrt
Copy link
Collaborator

coverrt commented Aug 22, 2022

Please test to ensure the current and proposed statements have consistent results.


db_selectTotalStageCount

The query plan for this statement may use temporary and filesort extras.

Format(szQuery, 512, "SELECT SUM(c.stages) FROM (SELECT a.mapname, MAX(zonetypeid)+2 as stages FROM `ck_zones` a RIGHT JOIN `ck_maptier` b ON a.mapname = b.mapname WHERE zonetype = 3 GROUP BY a.mapname)c");

Recommend statement

RIGHT JOIN changed to INNER JOIN to ensure the mapname column has matching values in both ck_zones and ck_maptier.

SELECT
    COUNT(DISTINCT `a`.`mapname`) + COUNT(1) AS `count`
FROM
    `ck_zones` `a`
INNER JOIN
    `ck_maptier` `b` ON
        `b`.`mapname` = `a`.`mapname`
WHERE
    `a`.`zonetype` = 3
    AND
    `a`.`zonegroup` = 0;

Current statement query plan

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ALL \N \N \N \N 1270
2 DERIVED b index PRIMARY PRIMARY 218 \N 254 Using index; Using temporary; Using filesort
2 DERIVED a ref PRIMARY PRIMARY 218 surftimer.b.mapname 5 Using where

Recommended statement query plan

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE b index PRIMARY PRIMARY 218 \N 254 Using index
1 SIMPLE a ref PRIMARY PRIMARY 218 surftimer.b.mapname 5 Using where

db_selectTotalBonusCount

Format(szQuery, 512, "SELECT COUNT(DISTINCT a.mapname,zonegroup) as count FROM ck_zones a RIGHT JOIN ck_maptier b ON a.mapname = b.mapname WHERE a.zonegroup > 0");

Recommended statement

Added additional WHERE clause for zonetype returning only start bonus zones, reducing records processed for aggregation.

RIGHT JOIN changed to INNER JOIN to ensure the mapname column has matching values in both ck_zones and ck_maptier.

SELECT
    COUNT(DISTINCT `a`.`mapname`, `a`.`zonegroup`) AS `count`
FROM
    `ck_zones` `a`
INNER JOIN
    `ck_maptier` `b` ON
        `b`.`mapname` = `a`.`mapname`
WHERE
    `a`.`zonetype` = 1
    AND
    `a`.`zonegroup` > 0;

Current statement query plan

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE b index PRIMARY PRIMARY 218 \N 254 Using index
1 SIMPLE a ref PRIMARY PRIMARY 218 surftimer.b.mapname 5 Using where

Recommended statement query plan

The query plan for this statement is not altered.

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE b index PRIMARY PRIMARY 218 \N 254 Using index
1 SIMPLE a ref PRIMARY PRIMARY 218 surftimer.b.mapname 5 Using where
@coverrt coverrt added the enhancement New feature or request label Aug 22, 2022
@RSCSurf
Copy link

RSCSurf commented Aug 22, 2022

Yeah, it would be better to use JOIN instead of RIGHT JOIN

1zc pushed a commit that referenced this issue Jan 28, 2023
@1zc 1zc closed this as completed Jan 28, 2023
dPexxIAM added a commit that referenced this issue Feb 10, 2023
* Test server should based on dev branch

* Allow pr tests against the dev branch

* Upload build packages for dev branch too

* Remove artifact after one month

* remove old code, wait 2 frames before setting velocity to 0 (#518)

* Update fresh_install.sql (#519)

Fixed errors.

* Add missing ck_replays table (#520)

* Fix version in error message (#521)

* --wrong value on check (#522)

* fix for #524 (#525)

* --fix style records/forwards

* --added oldtime var for styles
--added time difference between old and new server style record to printed phrase
--actually fixed issues(?)

* --missing set values for new var

* --missing indexation

* --wrong format

* Rename some files for clarity for updating tables

* Add semicolons (#528)

* Use LogStackTrace instead of LogError (#530)

Usage of sizeof instead of hardcoded size

* Add radar images to DownloadTable (#529)

* add radar images to download table

* remove colon from readme

* add surf load screens to readme

* Add EU test server to workflow

* Add EU test server to README.md

* Fix chat processor for our commands (#533)

* Log query times (#531)

* Hello World

* Hello World

* Print each query time into server console while startup

* Log query times into logs/surftimer/<map>.log logs

* Update globals.sp (#536)

if database name is greater than 32 then will get following error

[SM] Exception reported: More/Less then 1 rows? RowCount: 0, Table: ck_bonus, Column: runtime
[SM] Blaming: SurfTimer.smx
[SM] Call stack trace:
[SM]   [0] SetFailState
[SM]   [1] Line 241, surftimer/db/updater.sp::SQLCheckDataType

* Increase name length (#534)

* Increase name length from 32 to 128

* Increase name size per updater

* Add missing tables

* Update VARCHAR size in fresh_install.sql

* Skip error check to prevent invalid error

* 128 -> 64

* practice mode changes (#539)

* practice mode changes

* remove timer function

* forgot this timer seperates stuff into a million different functions :)

* add mapper names to ck_maptier (#538)

* add mapper names to ck_maptier

* use translation

* readme: improve installation + requirements docs (#537)

* readme: improve installation + requirements docs

* readme: EndTouchFix note update

* readme: EndTouchFix note update

* Fix SQL Error while creating ck_maptiermappers table

* or equal to prestige_rank (#541)

* Fix LoadDefaultTitle (only load the first one) (#543)

* Fix LoadDefaultTitle (only load the first one)

* If the title is enforced, break the loop

Co-authored-by: Ismael Semmar Galvez <isgalvez24@gmail.com>

* Missing mapper name argument for Map Info (#547)

* fix /mi

* revert and use g_szMapperName

* chore: small code cleanup (#545)

* fixes non-ranked players being kicked from server when ck_prestige_rank = 0 (#544)

* #506 (#548)

* fresh_install update (#551)

* increase cplimit from 37 to 100 (#552)

---------

Co-authored-by: dPexxIAM <38400978+dPexxIAM@users.noreply.github.com>
Co-authored-by: Jacob Christiansen <kin.jacob.chr@gmail.com>
Co-authored-by: shipyy <70631212+shipyy@users.noreply.github.com>
Co-authored-by: T <74899888+tslashd@users.noreply.github.com>
Co-authored-by: Kyle <kyle@kxnrl.com>
Co-authored-by: 8guawong <8guawong@gmail.com>
Co-authored-by: Markus <mark@saiko.tech>
Co-authored-by: Ismael Semmar Galvez <30930942+Ism1tha@users.noreply.github.com>
Co-authored-by: Ismael Semmar Galvez <isgalvez24@gmail.com>
Co-authored-by: Charles <63302440+Sarrus1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants