https://learninghub.kx.com/forums/topic/fast-insert-line-into-middle-of-an-in-memory-table
Hi Community,
We came across one issue in development.
Say we’ve got an in-memory table “tbl”, and want to insert “data” into this table regularly, not by appending, but inserting into specific row with “index”.
Currently we tried to do the following:
`tbl set (index#tbl), data, index _ tbl;
Question is:
Is there any suggested solution with decent performance as it would run multiple times.
Thanks in advance.
Xiaocheng
Hi Xiaocheng,
A few questions to add more context here;
- Assuming this process is an RDB, is there any particular reason you need to insert rows at a specific index?
- What logic determines the insert index?
For most RBD applications you probably want to avoid sorting until the end of day write down to disk.
If you need to increase performance in querying your RBD process, you could perhaps look at the grouped attribute, which will keep a hash map of the indices for the new rows.
q)tbl:update sym:`g#sym from ([]sym:upper 3?`4;price:3?10f);
q)meta tbl
c | t f a
-----| -----
sym | s g
price| f
q)tbl
sym price
--------------
GMEH 7.125845
IKOK 1.392257
CJEK 2.701876
q)tbl:tbl upsert (`ABCD;10f);
q)tbl
sym price
--------------
GMEH 7.125845
IKOK 1.392257
CJEK 2.701876
ABCD 10
q)meta tbl
c | t f a
-----| -----
sym | s g
price| f
Resources:
Hope this helps!
Cheers,
David