Thread: Performance of Bit String
Hi,<br /><br />I tried to store a BitString of length 2 million in a Postgres table (see code below), but it did not completeeven in 3 mins and then I cancelled it. Surprisingly, it only took few seconds when BitString was of length 500K.Is there any restriction of length of BitString or am I missing something here? <br /><br />create table bit_test(<br/> id smallint,<br /> memset bit(200000)<br /> ) ;<br /><br />DECLARE<br /> memset bit varying:= B'0';<br />BEGIN<br/> --PERFORM memset;<br /> FOR i In 1..2000000 LOOP<br /> memset := (memset || B'1') ; -- (B'1' << i);<br/> END LOOP;<br /><br /> INSERT INTO bit_test VALUES(1,B'1',memset :: bit(2000000));<br /><br />RETURN bit_length(memset);<br/>END;<br /><br /><br />Thanks,<br />Rupendra
Hi, Youre on the wrong list for this. This is not a -hackers (i.e. developer targeted) but a -general (user targeted) question. On Wednesday 09 June 2010 15:11:41 rupendra.chulyadyo@gmail.com wrote: > I tried to store a BitString of length 2 million in a Postgres table (see > code below), but it did not complete even in 3 mins and then I cancelled > it. Surprisingly, it only took few seconds when BitString was of length > 500K. Is there any restriction of length of BitString or am I missing > something here? I think youre missing that your algorithm for assembling the string has quadratic complexity. For each loop iteratoring the whole string will be newly allocated and then copied over. A faster way to create such a long string might be: SELECT array_to_string(array_agg(1),'')::bit(2000000) FROM generate_series(1, 2000000); Btw, your table definition has only the length bit(200k), but youre inserting bit(2000k)... What are you trying to achieve with such a long bitstring? Actually I cannot think of any database design where I would consider that a valid design- choice. Andres