Skip to content

Fix simulate query count#18583

Merged
MauricioFauth merged 9 commits intophpmyadmin:QA_5_2from
MoonE:fix-simulate-query
Aug 26, 2023
Merged

Fix simulate query count#18583
MauricioFauth merged 9 commits intophpmyadmin:QA_5_2from
MoonE:fix-simulate-query

Conversation

@MoonE
Copy link
Contributor

@MoonE MoonE commented Jul 26, 2023

Fixes #18533, closes #18536

@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.94% ⚠️

Comparison is base (135724f) 48.20% compared to head (93a8f20) 47.27%.

Additional details and impacted files
@@             Coverage Diff              @@
##             QA_5_2   #18583      +/-   ##
============================================
- Coverage     48.20%   47.27%   -0.94%     
- Complexity    17010    17011       +1     
============================================
  Files           607      607              
  Lines         72335    72342       +7     
============================================
- Hits          34870    34200     -670     
- Misses        37465    38142     +677     
Flag Coverage Δ
dbase-extension 48.05% <100.00%> (+0.06%) ⬆️
recode-extension 47.99% <100.00%> (-1.10%) ⬇️
unit-7.2-ubuntu-latest 47.95% <100.00%> (+0.01%) ⬆️
unit-7.3-ubuntu-latest 48.42% <100.00%> (+0.04%) ⬆️
unit-7.4-ubuntu-latest 48.42% <100.00%> (-0.01%) ⬇️
unit-8.0-ubuntu-latest 48.43% <100.00%> (-0.03%) ⬇️
unit-8.1-ubuntu-latest 48.51% <100.00%> (-0.01%) ⬇️
unit-8.2-ubuntu-latest 48.39% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...asses/Controllers/JavaScriptMessagesController.php 99.63% <ø> (-0.01%) ⬇️
libraries/classes/Plugins/Export/ExportJson.php 87.40% <ø> (ø)
libraries/classes/Import/SimulateDml.php 97.05% <100.00%> (+12.05%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MoonE MoonE force-pushed the fix-simulate-query branch 2 times, most recently from 6edfdfe to 7706ad6 Compare July 29, 2023 12:30
@MauricioFauth
Copy link
Member

MauricioFauth commented Aug 26, 2023

@MoonE Could you please rebase the PR?

@MoonE MoonE force-pushed the fix-simulate-query branch from 7706ad6 to fbaeff2 Compare August 26, 2023 19:33
MoonE added 9 commits August 26, 2023 21:35
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
@MoonE MoonE force-pushed the fix-simulate-query branch from fbaeff2 to 93a8f20 Compare August 26, 2023 19:36
@MauricioFauth MauricioFauth self-assigned this Aug 26, 2023
@MauricioFauth MauricioFauth added this to the 5.2.2 milestone Aug 26, 2023
@MauricioFauth MauricioFauth merged commit 69cc0a2 into phpmyadmin:QA_5_2 Aug 26, 2023
@MoonE MoonE deleted the fix-simulate-query branch August 26, 2023 20:01
Comment on lines +145 to +150
return 'SELECT COUNT(*)' .
' FROM (SELECT ' . implode(',', $newValues) . ') AS `pma_new`' .
' JOIN (' .
'SELECT ' . implode(', ', $oldValues) . ' FROM ' . $tableReferences[0] . $where . $order . $limit .
') AS `pma_old`' .
' WHERE NOT (' . implode(', ', $newColumns) . ') <=> (' . implode(', ', $oldColumns) . ')';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love if there was some comment explaining how this works because I can't comprehend it myself. :)

Copy link
Contributor Author

@MoonE MoonE Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pma_new selects the set values into a single row which is then joined with the current table as pma_old. No ON condition needed, as pma_new is always just a single row.
In the WHERE condition a tuple comparison is made that checks if the old data tuple is different to the new data tuple.
The outer select counts all rows that are different.

UPDATE `table_1` SET `id` = 1, `name` = 'asdf' WHERE `id` = 10
SELECT COUNT(*)
FROM (SELECT 1 AS `n0`, 'asdf' AS `n1`) AS `pma_new`
JOIN (SELECT `id` AS `o0`, `name` AS `o1` FROM `table_1` WHERE `id` = 1) AS `pma_old`
WHERE NOT (`n0`, `n1`) <=> (`o0`, `o1`)

Thinking about it ... this should be equivalent to this, placing the values directly in the WHERE condition:

SELECT COUNT(*)
FROM (SELECT `id` AS `o0`, `name` AS `o1` FROM `table_1` WHERE `id` = 1) AS `pma_old`
WHERE NOT (1, 'asdf') <=> (`o0`, `o1`)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MoonE I'm not sure about COUNT(*). Previously, when the number was clicked it would have shown the rows that will be updated, but now is only the count number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The count is the number of updated/affected rows. The pma_old subquery will give the matched rows, and the where condition reduces this to the affected rows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The count is the number of updated/affected rows. The pma_old subquery will give the matched rows, and the where condition reduces this to the affected rows

Yeah, but when the number is clicked, previously the rows where shown, something like:

count

Copy link
Contributor Author

@MoonE MoonE Aug 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about that ...

Though I'm not sure how useful this feature is. Just listing the updated values without a full row context?
It does make sense when deleting rows ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about that ...

Though I'm not sure how useful this feature is. Just listing the updated values without a full row context?

Well, the feature was there and probably someone might use this.

@MoonE MoonE mentioned this pull request Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants