My symbol column file size in partitioned table is unusually large -- why would that be?

Viewed 173

I've just built my first proper q/kdb+ database with splayed and partitioned tables. Everything is going fine, but I just noticed that my symbol s column file size is unusually large. Here is what I can see from the OS and from inside q:

# ls -latr 2017.10.30/ngbarx
total 532
-rw-r--r-- 1 root root  24992 Apr 17 20:53 vunadj
-rw-r--r-- 1 root root  24992 Apr 17 20:53 v
-rw-r--r-- 1 root root 300664 Apr 17 20:53 s
...

q)meta ngbarx
c     | t f a
------| -----
date  | d    
s     | s   p
v     | e    
vunadj| e    
...

q)get `:2017.10.30/ngbarx/s
`p#`sym$`A`AA`AACG`AADI`AADR`AAIC`AAIC-B`AAL`AAM-A`AAMC`AAME`AAOI`AAON`AAP`AA..

q)-22!get `:2017.10.30/ngbarx/v
24990
q)-22!get `:2017.10.30/ngbarx/s
28678
q)all (get `:2017.10.30/ngbarx/s) in sym
1b
q)count sym
62136

So comparing the real-type v column with the symbol-type s column, I see from ls that the symbol column is more than 10x the size, even though the internal size in bytes is similar and everything seems properly encoded in the sym file.

Is this expected behavior? Or am I doing something wrong that could be fixed?

UPDATE: I have not used compression, and have written the files using the magical function .Q.dcfgnt, which can be viewed here. Well, a slightly modified version, I noticed that this function as is also saved a date file in the directory, even though the column should be virtual, so I did some hacking in k (I'm not very good at it) and updated the inner function .Q.dpfgnt to this ...

k){[d;p;f;g;n;t]if[~&/qm'r:+en[d]t;'`unmappable];
 {[d;g;t;i;x]@[d;x;g;t[x]i]}[d:par[d;p;n];g;r;<r f]'{x@&~x=`date}(!r);
 @[;f;`p#]@[d;`.d;:;f,r@&~f=r:{x@&~x=`date}(!r)];n}
1 Answers

Applying the parted attribute is not free and requires storage. It is usually not that costly but looking at your sample output of s, it doesn't look suitable for parting as does not contain repeating values:

q)get `:2017.10.30/ngbarx/s
`p#`sym$`A`AA`AACG`AADI`AADR`AAIC`AAIC-B`AAL`AAM-A`AAMC`AAME`AAOI`AAON`AAP`AA..

See below tables created to illustrate the issue:

/ no part - 16 distinct syms
t1:([]s:100000?`1;v:100000?2e)

/ part - 16 distinct syms
t2:update `p#s from `s xasc ([]s:100000?`1;v:100000?2e)

/ no part - 99999 distinct syms
t3:([]s:100000?`8;v:100000?2e)

/ part - 99999 distinct syms
t4:update `p#s from `s xasc ([]s:100000?`8;v:100000?2e)

The difference in size is insignificant between t1 and t2 with the parted attribute(804096 -> 804664). However, when the number of distinct syms / parts becomes very large, the storage cost is very large. (804096 -> 4749872)

ls | xargs ls -latr
t1:
total 1180
-rw-r--r-- 1 matmoore matmoore     12 Apr 19 10:28 .d
-rw-r--r-- 1 matmoore matmoore 804096 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore   4096 Apr 19 10:28 .
drwxr-xr-x 1 matmoore matmoore   4096 Apr 19 10:28 ..

t2:
total 1180
-rw-r--r-- 1 matmoore matmoore     12 Apr 19 10:28 .d
-rw-r--r-- 1 matmoore matmoore 804664 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore   4096 Apr 19 10:28 .
drwxr-xr-x 1 matmoore matmoore   4096 Apr 19 10:28 ..

t3:
total 1180
-rw-r--r-- 1 matmoore matmoore     12 Apr 19 10:28 .d
-rw-r--r-- 1 matmoore matmoore 804096 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore   4096 Apr 19 10:28 .
drwxr-xr-x 1 matmoore matmoore   4096 Apr 19 10:28 ..

t4:
total 5032
-rw-r--r-- 1 matmoore matmoore      12 Apr 19 10:28 .d
drwxr-xr-x 1 matmoore matmoore    4096 Apr 19 10:28 ..
-rw-r--r-- 1 matmoore matmoore 4749872 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore  400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore    4096 Apr 19 10:28 .

I would also question if this column should be a symbol. If 62k is the size of your sym file with just one date created then you should be careful that you are going to end up creating a bloated sym file. If you have a full history from 2017.10.30 and the sym file is still 62k, then it's fine but if you are adding that many new symbols each day, the sym file will quickly spiral out of control.

Related