Search code examples
kdb

kdb: Efficient way to delete last row from a table?


For example, creating this 20M row table takes 37ms, but deleting a row takes 38ms! Is there any way to do this more efficiently? (In place modify is fine as I don't need the original)

q)n:20000000
q)t:([]a:n#1;b:n#2)
q)\t t:([]a:n#1;b:n#2)
37
q)\t t:-1_t
38

/ in place delete doesn't seem to help either
q)\t delete from `t where i=last i
67

Solution

  • No. Various approaches you would hope to work are limited by the fact that a copy of t is being created (inspect the peak value of .Q.w[] before and after either your delete query or using Drop if you need convinced of this). Your lowerbound on execution is going to be limited by the time it takes to construct t.