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

Weird behavior with WHERE clause #1063

Open
tbantle22 opened this issue Dec 11, 2024 · 2 comments
Open

Weird behavior with WHERE clause #1063

tbantle22 opened this issue Dec 11, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@tbantle22
Copy link
Contributor

I noticed that sometimes deleting a row using the Dolt Workbench sometimes doesn't work.

To repro, follow the Doltgres getting started guide here

Add schemas:

newdb=> create table employees (
    id int8,
    last_name text,
    first_name text,
    primary key(id));
CREATE TABLE
newdb=> create table teams (
    id int8,
    team_name text,
    primary key(id));
CREATE TABLE
newdb=> create table employees_teams(
    team_id int8,
    employee_id int8,
    primary key(team_id, employee_id),
    foreign key (team_id) references teams(id),
    foreign key (employee_id) references employees(id));
CREATE TABLE
newdb=> \d
              List of relations
 Schema |      Name       | Type  |  Owner
--------+-----------------+-------+----------
 public | employees       | table | postgres
 public | employees_teams | table | postgres
 public | teams           | table | postgres
(3 rows)

newdb=> select dolt_commit('-Am', 'Created initial schema');
            dolt_commit
------------------------------------
 {dmgebsbblrlcs3o0ju314d46c6qkgjer}
(1 row)

Insert rows:

newdb=> insert into employees values
    (0, 'Sehn', 'Tim'),
    (1, 'Hendriks', 'Brian'),
    (2, 'Son','Aaron'),
    (3, 'Fitzgerald', 'Brian');
INSERT 0 4
newdb=> select * from employees where first_name='Brian';
 id | last_name  | first_name
----+------------+------------
  1 | Hendriks   | Brian
  3 | Fitzgerald | Brian
(2 rows)

newdb=> insert into teams values
    (0, 'Engineering'),
    (1, 'Sales');
INSERT 0 2
newdb=> insert into employees_teams(employee_id, team_id) values
    (0,0),
    (1,0),
    (2,0),
    (0,1),
    (3,1);
INSERT 0 5
newdb=> select dolt_commit('-am', 'Populated tables with data');
            dolt_commit
------------------------------------
 {7eeno6vrmqg0rg17ep3sc5pidbsttjfq}
(1 row)

Now the employees_teams table looks like this:

newdb=> select * from employees_teams;
 team_id | employee_id
---------+-------------
       0 |           0
       0 |           1
       0 |           2
       1 |           0
       1 |           3
(5 rows)

But if I want to select * from employees_teams with a where clause, it works for some IDs and not for other IDs.

Works:

newdb=> select * from employees_teams where team_id=0 and employee_id=0;
 team_id | employee_id
---------+-------------
       0 |           0
(1 row)

Returns 0 rows when it shouldn't:

newdb=> select * from employees_teams where team_id=1 and employee_id=0;
 team_id | employee_id
---------+-------------
(0 rows)

I also cannot delete that row:

newdb=> delete from employees_teams where team_id=1 and employee_id=0;
DELETE 0
newdb=> select * from employees_teams;
 team_id | employee_id
---------+-------------
       0 |           0
       0 |           1
       0 |           2
       1 |           0
       1 |           3
(5 rows)

I didn't see this behavior using where clauses with the employees or teams tables

@tbantle22 tbantle22 added the bug Something isn't working label Dec 11, 2024
@zachmu
Copy link
Member

zachmu commented Dec 12, 2024

Seems like this is probably an index matching issue. Thanks for the repro!

@tbantle22
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants