Skip to content

Update with subselect in WHERE clause silently fails to update #9268

Closed
dolthub/go-mysql-server
#3000
@srabraham

Description

@srabraham

Hi there,
I encountered this problem in my real system, but here's a contrived simple example:

-- make a table mapping an ID to a bool
create table MY_TABLE (
    ID int not null primary key,
    MY_BOOL bool not null
);

-- insert one row
insert into MY_TABLE values (0, false);

-- this correctly returns 0
select MY_BOOL from MY_TABLE;

-- this should set MY_BOOL to 1
update MY_TABLE
set MY_BOOL = true
where ID in (
    select 0
);

-- but it didn't. This still returns 0
select MY_BOOL from MY_TABLE;

-- this does work though
update MY_TABLE
set MY_BOOL = true
where ID = 0;

-- returns 1
select MY_BOOL from MY_TABLE;

Activity

timsehn

timsehn commented on May 29, 2025

@timsehn
SponsorContributor

I'm going to move this to Dolt for more visibility.

added
bugSomething isn't working
sqlIssue with SQL
correctnessWe don't return the same result as MySQL
on May 29, 2025
angelamayxie

angelamayxie commented on May 29, 2025

@angelamayxie
Contributor

This is what I get in dolt

tmp/main*> create table MY_TABLE (ID int not null primary key, MY_BOOL bool not null);
tmp/main*> insert into MY_TABLE values (0, false);
Query OK, 1 row affected (0.00 sec)
tmp/main*> select MY_BOOL from MY_TABLE;
+---------+
| MY_BOOL |
+---------+
| 0       |
+---------+
1 row in set (0.00 sec) 


tmp/main*> update MY_TABLE set MY_BOOL = true where ID in (select 0);
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
tmp/main*> select MY_BOOL from MY_TABLE;
+---------+
| MY_BOOL |
+---------+
| 0       |
+---------+
1 row in set (0.00 sec) 

versus what I get in mysql

mysql> create table MY_TABLE (ID int not null primary key, MY_BOOL bool not null);
Query OK, 0 rows affected (0.01 sec)

mysql> insert MY_TABLE values (0, false);
Query OK, 1 row affected (0.00 sec)

mysql> select MY_BOOL from MY_TABLE;
+---------+
| MY_BOOL |
+---------+
|       0 |
+---------+
1 row in set (0.01 sec)

mysql> update MY_TABLE set MY_BOOL = true where ID in (select 0);
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select MY_BOOL from MY_TABLE;
+---------+
| MY_BOOL |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)

Note that dolt is able to match the row but does not update it. Dolt is also missing Query OK, 0 rows affected (0.01 sec) after the initial create table

self-assigned this
on May 29, 2025
jycor

jycor commented on May 30, 2025

@jycor
Contributor

Hey @srabraham, we've merged the fix for this issue to GMS main.
It's on its way to dolt main, and we'll cut a release for you later tonight.

srabraham

srabraham commented on May 30, 2025

@srabraham
Author

You rock! Thanks!

bpf120

bpf120 commented on May 30, 2025

@bpf120

@srabraham , thanks for filing! We'd love to learn about your Dolt use case too. Feel free to email me or swing by our Discord if you would like to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingcorrectnessWe don't return the same result as MySQLcustomer issuesqlIssue with SQL

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @timsehn@angelamayxie@srabraham@jycor@coffeegoddd

    Issue actions

      Update with subselect in WHERE clause silently fails to update · Issue #9268 · dolthub/dolt