Empty result if all columns of primary key are part of the WHERE conditions
See original GitHub issueCrateDB version: 1.1.2 and 1.1.5
JVM version: Java 8
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
OS version / environment description: Ubuntu 14.04.5 LTS - amd64
Problem description: If I try to run a SELECT or DELETE statement, where all columns of the primary key are part of the WHERE condition, Crate always return an empty result or don’t delete the record.
Steps to reproduce:
Create schema and import testing data
create table statusengine_host_scheduleddowntimes_test (
hostname string,
entry_time timestamp,
author_name string,
comment_data string,
internal_downtime_id int,
triggered_by_id int,
is_fixed boolean,
duration int,
scheduled_start_time timestamp,
scheduled_end_time timestamp,
was_started boolean,
actual_start_time timestamp,
node_name string,
PRIMARY KEY ("hostname", "node_name", "scheduled_start_time", "internal_downtime_id")
) CLUSTERED INTO 4 shards with (number_of_replicas = '1-all');
INSERT INTO statusengine_host_scheduleddowntimes_test (hostname, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time, was_started, actual_start_time, node_name)VALUES
('hplj2605dn', 1497981544, 'Anonymous', '60sekunden111', 12, 0, true, 60, 1497981638, 1497981698, true, 1497981638, 'Crowbar'),
('hplj2605dn', 1497903139, 'Anonymous', '300sekunden111', 7, 0, true, 300, 1497903501, 1497903801, true, 1497903501, 'Crowbar'),
('hplj2605dn', 1497982034, 'Anonymous', '60sekunden222', 14, 0, true, 300, 1497982068, 1497982128, true, 1497982068, 'Crowbar');
Query i like the execute, which always return nothing
select * from statusengine_host_scheduleddowntimes_test where hostname='hplj2605dn' and node_name='Crowbar' AND scheduled_start_time=1497981638 and internal_downtime_id=12;
As you can see, i use all primary key columns in the WHERE condition…
I also noticed, that a SELECT count(*) will return 1.
select Count(*) from statusengine_host_scheduleddowntimes_test where hostname='hplj2605dn' and node_name='Crowbar' AND scheduled_start_time=1497981638 and internal_downtime_id=12 limit 100;
As workaround i need to add a random column from the table as well
select * from statusengine_host_scheduleddowntimes_test where hostname='hplj2605dn' and node_name='Crowbar' AND scheduled_start_time=1497981638 and internal_downtime_id=12 and duration=60 limit 100;
Did i just miss something?
//Update Same results on a 3 node CrateDB cluster on Version 1.1.2 as on my single node dev system at 1.1.5
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
NULL value in multi-column primary key - mysql - Stack Overflow
A unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL...
Read more >Primary and Foreign Key Constraints - SQL Server
For this constraint to execute, all foreign key columns must have default definitions. If a column is nullable, and there is no explicit...
Read more >Constraints in SQL Server: SQL NOT NULL, UNIQUE and SQL ...
This article explains the useful constraints SQL NOT NULL, Unique and Primary Key constraints in SQL Server examples with user cases.
Read more >CONSTRAINT clause
A UNIQUE constraint defines a set of columns that uniquely identify rows in a table only if all the key values are not...
Read more >SQL - Primary Key - Tutorialspoint
A primary key is a field in a table which uniquely identifies each row/record in a database table. Primary keys must contain unique...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nook24 @grestocla this isssue has been fixed by https://github.com/crate/crate/commit/919fec3c4e47f61336d8db9970b42a9bb7b408ed and will be released with the next hotfix releases. thanks for reporting!
@seut, I’m not sure if i got you right. Did you mean that I need to define the columns in the same order in my crate table statement:
Or did you mean, that I need to pass the columns in the WHERE condition in the same order, as they are defined in the PK? Because in my example query, they are already in the same order as in the PK definition…
and this is returning an empty result set.
@grestocla Nice idea. Based on this i found an other workaround. I just need to cast the
internal_downtime_id
from integer to integer, this works as well//Update Ordering the columns doesn’t seems to be the fix
Same behavior… Looks like CAST() or add a column which is not defined the the PK is the only workaround at the moment
//Update 2 @seut Sorry, missed the
INSERT INTO
part… Yes, looks like this is working as well 😃