You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Tommy Stendahl <to...@ericsson.com> on 2015/08/28 13:14:08 UTC

TTL question

Hi,

I did a small test using TTL but I didn't get the result I expected.

I did this in sqlsh:

cqlsh> create TABLE foo.bar ( key int, cluster int, col int, PRIMARY KEY 
(key, cluster)) ;
cqlsh> INSERT INTO foo.bar (key, cluster ) VALUES ( 1,1 );
cqlsh> SELECT * FROM foo.bar ;

  key | cluster | col
-----+---------+------
    1 |       1 | null

(1 rows)
cqlsh> INSERT INTO foo.bar (key, cluster, col ) VALUES ( 1,1,1 ) USING 
TTL 10;
cqlsh> SELECT * FROM foo.bar ;

  key | cluster | col
-----+---------+-----
    1 |       1 |   1

(1 rows)

<wait for TTL to expire>

cqlsh> SELECT * FROM foo.bar ;

  key | cluster | col
-----+---------+-----

(0 rows)



Is this really correct?
I expected the result from the last select to be:

  key | cluster | col
-----+---------+------
    1 |       1 | null

(1 rows)


Regards,
Tommy

Re: TTL question

Posted by Robert Coli <rc...@eventbrite.com>.
On Fri, Aug 28, 2015 at 6:27 AM, Tommy Stendahl <tommy.stendahl@ericsson.com
> wrote:

> Thx, that was the problem. When I think about it it makes sense that I
> should use update in this scenario and not insert.


Per Sylvain on an old thread :

"
INSERT and UPDATE are not totally orthogonal in CQL and you should use
INSERT for actual insertion and UPDATE for updates (granted, the database
will not reject your query if you break this rule but it's nonetheless the
way it's intended to be used).
"

=Rob

Re: TTL question

Posted by Tommy Stendahl <to...@ericsson.com>.
Thx, that was the problem. When I think about it it makes sense that I 
should use update in this scenario and not insert.

cqlsh> create TABLE foo.bar ( key int, cluster int, col int, PRIMARY KEY 
(key, cluster)) ;
cqlsh> INSERT INTO foo.bar (key, cluster ) VALUES ( 1,1 );
cqlsh> SELECT * FROM foo.bar ;

  key | cluster | col
-----+---------+------
    1 |       1 | null

(1 rows)
cqlsh> UPDATE foo.bar USING TTL 10 SET col = 1 WHERE key = 1 AND cluster 
= 1;
cqlsh> SELECT * FROM foo.bar ;

  key | cluster | col
-----+---------+-----
    1 |       1 |   1

(1 rows)

<wait for TTL to expire>

cqlsh> SELECT * FROM foo.bar ;

  key | cluster | col
-----+---------+------
    1 |       1 | null

(1 rows)

/Tommy

On 2015-08-28 14:20, Jacques-Henri Berthemet wrote:
> What if you use an update statement in the second query?
>
> --
> Jacques-Henri Berthemet
>
> -----Original Message-----
> From: Tommy Stendahl [mailto:tommy.stendahl@ericsson.com]
> Sent: vendredi 28 août 2015 13:34
> To: user@cassandra.apache.org
> Subject: Re: TTL question
>
> Yes, I understand that but I think this gives a strange behaviour.
> Having values only on the primary key columns are perfectly valid so why
> should the primary key be deleted by the TTL on the non-key column.
>
> /Tommy
>
> On 2015-08-28 13:19, Marcin Pietraszek wrote:
>> Please look at primary key which you've defined. Second mutation has
>> exactly the same primary key - it overwrote row that you previously
>> had.
>>
>> On Fri, Aug 28, 2015 at 1:14 PM, Tommy Stendahl
>> <to...@ericsson.com> wrote:
>>> Hi,
>>>
>>> I did a small test using TTL but I didn't get the result I expected.
>>>
>>> I did this in sqlsh:
>>>
>>> cqlsh> create TABLE foo.bar ( key int, cluster int, col int, PRIMARY KEY
>>> (key, cluster)) ;
>>> cqlsh> INSERT INTO foo.bar (key, cluster ) VALUES ( 1,1 );
>>> cqlsh> SELECT * FROM foo.bar ;
>>>
>>>    key | cluster | col
>>> -----+---------+------
>>>      1 |       1 | null
>>>
>>> (1 rows)
>>> cqlsh> INSERT INTO foo.bar (key, cluster, col ) VALUES ( 1,1,1 ) USING TTL
>>> 10;
>>> cqlsh> SELECT * FROM foo.bar ;
>>>
>>>    key | cluster | col
>>> -----+---------+-----
>>>      1 |       1 |   1
>>>
>>> (1 rows)
>>>
>>> <wait for TTL to expire>
>>>
>>> cqlsh> SELECT * FROM foo.bar ;
>>>
>>>    key | cluster | col
>>> -----+---------+-----
>>>
>>> (0 rows)
>>>
>>>
>>>
>>> Is this really correct?
>>> I expected the result from the last select to be:
>>>
>>>    key | cluster | col
>>> -----+---------+------
>>>      1 |       1 | null
>>>
>>> (1 rows)
>>>
>>>
>>> Regards,
>>> Tommy
>>



RE: TTL question

Posted by Jacques-Henri Berthemet <ja...@genesys.com>.
What if you use an update statement in the second query?

--
Jacques-Henri Berthemet

-----Original Message-----
From: Tommy Stendahl [mailto:tommy.stendahl@ericsson.com] 
Sent: vendredi 28 août 2015 13:34
To: user@cassandra.apache.org
Subject: Re: TTL question

Yes, I understand that but I think this gives a strange behaviour. 
Having values only on the primary key columns are perfectly valid so why 
should the primary key be deleted by the TTL on the non-key column.

/Tommy

On 2015-08-28 13:19, Marcin Pietraszek wrote:
> Please look at primary key which you've defined. Second mutation has
> exactly the same primary key - it overwrote row that you previously
> had.
>
> On Fri, Aug 28, 2015 at 1:14 PM, Tommy Stendahl
> <to...@ericsson.com> wrote:
>> Hi,
>>
>> I did a small test using TTL but I didn't get the result I expected.
>>
>> I did this in sqlsh:
>>
>> cqlsh> create TABLE foo.bar ( key int, cluster int, col int, PRIMARY KEY
>> (key, cluster)) ;
>> cqlsh> INSERT INTO foo.bar (key, cluster ) VALUES ( 1,1 );
>> cqlsh> SELECT * FROM foo.bar ;
>>
>>   key | cluster | col
>> -----+---------+------
>>     1 |       1 | null
>>
>> (1 rows)
>> cqlsh> INSERT INTO foo.bar (key, cluster, col ) VALUES ( 1,1,1 ) USING TTL
>> 10;
>> cqlsh> SELECT * FROM foo.bar ;
>>
>>   key | cluster | col
>> -----+---------+-----
>>     1 |       1 |   1
>>
>> (1 rows)
>>
>> <wait for TTL to expire>
>>
>> cqlsh> SELECT * FROM foo.bar ;
>>
>>   key | cluster | col
>> -----+---------+-----
>>
>> (0 rows)
>>
>>
>>
>> Is this really correct?
>> I expected the result from the last select to be:
>>
>>   key | cluster | col
>> -----+---------+------
>>     1 |       1 | null
>>
>> (1 rows)
>>
>>
>> Regards,
>> Tommy
>
>


Re: TTL question

Posted by Tommy Stendahl <to...@ericsson.com>.
Yes, I understand that but I think this gives a strange behaviour. 
Having values only on the primary key columns are perfectly valid so why 
should the primary key be deleted by the TTL on the non-key column.

/Tommy

On 2015-08-28 13:19, Marcin Pietraszek wrote:
> Please look at primary key which you've defined. Second mutation has
> exactly the same primary key - it overwrote row that you previously
> had.
>
> On Fri, Aug 28, 2015 at 1:14 PM, Tommy Stendahl
> <to...@ericsson.com> wrote:
>> Hi,
>>
>> I did a small test using TTL but I didn't get the result I expected.
>>
>> I did this in sqlsh:
>>
>> cqlsh> create TABLE foo.bar ( key int, cluster int, col int, PRIMARY KEY
>> (key, cluster)) ;
>> cqlsh> INSERT INTO foo.bar (key, cluster ) VALUES ( 1,1 );
>> cqlsh> SELECT * FROM foo.bar ;
>>
>>   key | cluster | col
>> -----+---------+------
>>     1 |       1 | null
>>
>> (1 rows)
>> cqlsh> INSERT INTO foo.bar (key, cluster, col ) VALUES ( 1,1,1 ) USING TTL
>> 10;
>> cqlsh> SELECT * FROM foo.bar ;
>>
>>   key | cluster | col
>> -----+---------+-----
>>     1 |       1 |   1
>>
>> (1 rows)
>>
>> <wait for TTL to expire>
>>
>> cqlsh> SELECT * FROM foo.bar ;
>>
>>   key | cluster | col
>> -----+---------+-----
>>
>> (0 rows)
>>
>>
>>
>> Is this really correct?
>> I expected the result from the last select to be:
>>
>>   key | cluster | col
>> -----+---------+------
>>     1 |       1 | null
>>
>> (1 rows)
>>
>>
>> Regards,
>> Tommy
>
>


Re: TTL question

Posted by Marcin Pietraszek <mp...@opera.com>.
Please look at primary key which you've defined. Second mutation has
exactly the same primary key - it overwrote row that you previously
had.

On Fri, Aug 28, 2015 at 1:14 PM, Tommy Stendahl
<to...@ericsson.com> wrote:
> Hi,
>
> I did a small test using TTL but I didn't get the result I expected.
>
> I did this in sqlsh:
>
> cqlsh> create TABLE foo.bar ( key int, cluster int, col int, PRIMARY KEY
> (key, cluster)) ;
> cqlsh> INSERT INTO foo.bar (key, cluster ) VALUES ( 1,1 );
> cqlsh> SELECT * FROM foo.bar ;
>
>  key | cluster | col
> -----+---------+------
>    1 |       1 | null
>
> (1 rows)
> cqlsh> INSERT INTO foo.bar (key, cluster, col ) VALUES ( 1,1,1 ) USING TTL
> 10;
> cqlsh> SELECT * FROM foo.bar ;
>
>  key | cluster | col
> -----+---------+-----
>    1 |       1 |   1
>
> (1 rows)
>
> <wait for TTL to expire>
>
> cqlsh> SELECT * FROM foo.bar ;
>
>  key | cluster | col
> -----+---------+-----
>
> (0 rows)
>
>
>
> Is this really correct?
> I expected the result from the last select to be:
>
>  key | cluster | col
> -----+---------+------
>    1 |       1 | null
>
> (1 rows)
>
>
> Regards,
> Tommy



-- 
--
Marcin Pietraszek