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

Select query with join sometimes returns empty set #8096

Open
tbantle22 opened this issue Jul 2, 2024 · 0 comments
Open

Select query with join sometimes returns empty set #8096

tbantle22 opened this issue Jul 2, 2024 · 0 comments
Assignees
Labels
bug Something isn't working sql Issue with SQL

Comments

@tbantle22
Copy link
Contributor

tbantle22 commented Jul 2, 2024

A query in our hostedapi database (dolt version 1.35.10) sometimes returns an empty set when it shouldn't.

mysql> SELECT email_addresses.* FROM email_addresses JOIN `users` ON email_addresses.id = users.primary_email_fk WHERE users.id = '2a1e3627-6b0d-4788-b3d9-27bb83f059e7';
Empty set (0.01 sec)

mysql> SELECT email_addresses.* FROM email_addresses JOIN `users` ON email_addresses.id = users.primary_email_fk WHERE users.id = '2a1e3627-6b0d-4788-b3d9-27bb83f059e7';
+--------------------------------------+--------------------------------------+-----------------+-------------+---------------------+---------------------+
| id                                   | user_id_fk                           | address         | is_verified | updated_at          | created_at          |
+--------------------------------------+--------------------------------------+-----------------+-------------+---------------------+---------------------+
| 0e85068d-9afd-448a-be20-48854ebb8baf | 2a1e3627-6b0d-4788-b3d9-27bb83f059e7 | max@dolthub.com |           1 | 2024-02-16 22:32:03 | 2024-02-16 22:32:03 |
+--------------------------------------+--------------------------------------+-----------------+-------------+---------------------+---------------------+
1 row in set (0.00 sec)

These are the schemas of the users and email_addresses tables:

mysql> show create table users;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
  `id` varchar(36) NOT NULL,
  `name` varchar(32) NOT NULL,
  `display_name` varchar(128),
  `company` varchar(128),
  `updated_at` timestamp(6),
  `created_at` timestamp(6),
  `primary_email_fk` varchar(36),
  `saml_provider_id_fk` varchar(36),
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `primary_email_fk` (`primary_email_fk`),
  KEY `saml_provider_id_fk` (`saml_provider_id_fk`),
  CONSTRAINT `2gv1aord` FOREIGN KEY (`primary_email_fk`) REFERENCES `email_addresses` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `users_saml_provider_id_fk_constraint` FOREIGN KEY (`saml_provider_id_fk`) REFERENCES `saml_identity_providers` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create table email_addresses;
+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table           | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| email_addresses | CREATE TABLE `email_addresses` (
  `id` varchar(36) NOT NULL,
  `user_id_fk` varchar(36),
  `address` varchar(320) NOT NULL,
  `is_verified` tinyint NOT NULL,
  `updated_at` timestamp(6),
  `created_at` timestamp(6),
  PRIMARY KEY (`id`),
  UNIQUE KEY `address` (`address`),
  UNIQUE KEY `id` (`id`),
  KEY `user_id_fk` (`user_id_fk`),
  CONSTRAINT `etjvpu9s` FOREIGN KEY (`user_id_fk`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

The user and email address IDs both exist:

mysql> select * from users where id = '2a1e3627-6b0d-4788-b3d9-27bb83f059e7';
+--------------------------------------+-------------+--------------+---------+---------------------+---------------------+--------------------------------------+---------------------+
| id                                   | name        | display_name | company | updated_at          | created_at          | primary_email_fk                     | saml_provider_id_fk |
+--------------------------------------+-------------+--------------+---------+---------------------+---------------------+--------------------------------------+---------------------+
| 2a1e3627-6b0d-4788-b3d9-27bb83f059e7 | max-hoffman |              |         | 2024-02-16 22:32:03 | 2024-02-16 22:32:03 | 0e85068d-9afd-448a-be20-48854ebb8baf | NULL                |
+--------------------------------------+-------------+--------------+---------+---------------------+---------------------+--------------------------------------+---------------------+
1 row in set (0.00 sec)

mysql> select * from email_addresses where id='0e85068d-9afd-448a-be20-48854ebb8baf';
+--------------------------------------+--------------------------------------+-----------------+-------------+---------------------+---------------------+
| id                                   | user_id_fk                           | address         | is_verified | updated_at          | created_at          |
+--------------------------------------+--------------------------------------+-----------------+-------------+---------------------+---------------------+
| 0e85068d-9afd-448a-be20-48854ebb8baf | 2a1e3627-6b0d-4788-b3d9-27bb83f059e7 | max@dolthub.com |           1 | 2024-02-16 22:32:03 | 2024-02-16 22:32:03 |
+--------------------------------------+--------------------------------------+-----------------+-------------+---------------------+---------------------+
1 row in set (0.00 sec)
@tbantle22 tbantle22 added bug Something isn't working sql Issue with SQL labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

2 participants