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

SyntaxConformanceTest::testSqlOperators - Fix failure on MySQL 8 #17262

Merged
merged 1 commit into from
May 8, 2020

Conversation

totten
Copy link
Member

@totten totten commented May 8, 2020

Before

SyntaxConformanceTest::testSqlOperators frequently fails on the Dedupe entity when running on MySQL 8 (bknix-edge).

After

SyntaxConformanceTest::testSqlOperators repeatedly passes for all entities on my copy of MySQL 8 (bknix-edge).

Technical Details

The testSqlOperators creates a small pool of example records ($entities), then it slices/dices that pool with a few SQL operators and asserts the number of matches.

In particular:

$this->callAPISuccessGetCount($entityName,
  ['id' => ['>' => $entities[0]]], 
  $totalEntities - 1);

The problem is that $entities[0] does not necessarily have the lowest ID -- because $entities was not fetched in any particular order. The default ordering is often the same as the id, but not always.

I suspect that this problem manifests most frequently with the Dedupe entity because the underlying table (civicrm_prevnext_cache) is highly volatile (many writes+deletes) -- thus it's more likely to reuse old storage slots for new rows.

IMHO, the problem ought to occur in many SQL environments, but the frequency of occurrence seems to vary by version.

Before
------

`SyntaxConformanceTest::testSqlOperators` frequently fails on the `Dedupe` entity when running on MySQL 8 (`bknix-edge`).

After
------

`SyntaxConformanceTest::testSqlOperators` repeatedly passes for all entities on my copy of MySQL 8 (`bknix-edge`).

Technical Details
-----------------

The `testSqlOperators` creates a small pool of example records
(`$entities`), then it slices/dices that pool with a few SQL operators and
asserts the number of matches.

In particular:

```php
$this->callAPISuccessGetCount($entityName, ['id' => ['>' => $entities[0]]], $totalEntities - 1);
```

The problem is that `$entities[0]` does not necessarily have the lowest ID
-- because `$entities` was not fetched in any particular order.  The default
ordering is *often* the same as the `id`, but not always.

I suspect that this problem manifests most frequently with the `Dedupe`
entity because the underlying table (`civicrm_prevnext_cache`) is highly
volatile (many writes+deletes) -- thus it's more likely to reuse old storage
slots for new rows.
@civibot
Copy link

civibot bot commented May 8, 2020

(Standard links)

@civibot civibot bot added the master label May 8, 2020
@seamuslee001
Copy link
Contributor

Change makes sense and passed on a small test run on edge matrix

@seamuslee001 seamuslee001 changed the base branch from master to 5.26 May 8, 2020 08:34
@civibot civibot bot added 5.26 and removed master labels May 8, 2020
@seamuslee001 seamuslee001 merged commit fd525a9 into civicrm:5.26 May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants