nataraj: (Бритый небритый)
My colleague Alex_Ignatov@facebook.com found curious behavior of random():

postgres=# select (select random() as value ) from generate_series(1,10) as k;
       value       
-------------------
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
 0.715956253930926
(10 rows)


Something like
int rnd=5; // This figure is really random. Got it by rolling a die

;-)
nataraj: (Бритый небритый)
While rewriting reloption.c code, I came to an idea, that all string reloptions that are used in the code are actually enum reloptions: just a fixed list of string constants, nothing more.

Read more... )

PS. If you would like to comment this post, please login from any social network that is possible to login here, or at least write your name, so I would be able to answer you...
nataraj: (Бритый небритый)
When you are creating table in postgres, you are creating up to two relations in a row.
In case when you create table with fixed-length attributes only, only one relation is created. A heap relation.
If you have at least one variable-length attribute in your table, then both heap and toast relations will be created.

Relations also have options: reloptions. You can set them while creating and altering table. To set options for toast relations you should use toast. prefix before reloption name:
CREATE TABLE reloptions_test (s varchar) WITH (toast.autovacuum_vacuum_cost_delay = 23 );

The only problem is that if you have table with no varlen values, postgres will accept toast reloption, but will not write it anywhere.
#CREATE TABLE reloptions_test (i int) WITH (toast.autovacuum_vacuum_cost_delay = 23 );
CREATE TABLE
# select reltoastrelid from pg_class where oid = 'reloptions_test'::regclass;
 reltoastrelid 
---------------
             0
(1 row)

there is no toast relation and reloption is not saved at all, postgres reports, everything is ok

Same for alter table:
# ALTER TABLE reloptions_test SET (toast.autovacuum_vacuum_cost_delay = 24 );
ALTER TABLE
# select reltoastrelid from pg_class where oid = 'reloptions_test'::regclass;
 reltoastrelid 
---------------
             0
(1 row)

This is not nice behavior, isn't it?

PS please when writing a comment, login with any account you have, or just leave a name and/or e-mail so I will be able to answer that comment ;-)
nataraj: (Бритый небритый)
It seems to me that I found a bug in current implementation of reloptions: When you are creating a custom index with it's own reloptions, you have no ways to prevent it from changing using ALTER INDEX .... SET (op=value);
For example if you do for bloom index
alter index bloomidx set ( length=15 );

postgres will successfully run this, change the value of reloptions attribute in pg_class, and bloom index will work wrong after it.
And there is no way to forbid this from inside of an extension.

I think I would add there a flag in reloption descriptor that will tell whether it is allowed to change this reloption using ALTER INDEX, or not
nataraj: (Бритый небритый)
While trying to add something useful into INSERT statement, I wrote more simple example, just to find out how it should work.
I think this might be helpful to people that also want to hack into that area.

Example is very simple, it adds keyword TEST into the definition of attribute list into CREATE INDEX statement, and in ComputeIndexAttrs it says using elog(WARNING ...) whether it found TEST keyword or not.

postgres=# create index  ON mytable (i TEST 'value');
WARNING:  Creating index for column i with TEST value
CREATE INDEX 
postgres=# create index  ON mytable  (i);
WARNING:  TEST is empty
CREATE INDEX


This example is not for production development, it just shows what part of code you should touch in order to modify grammar.

grammar_example.diff )

Profile

nataraj: (Default)
Swami Dhyan Nataraj

July 2017

S M T W T F S
      1
2345678
9 101112 131415
16171819202122
23242526272829
3031     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 25th, 2017 10:38 pm
Powered by Dreamwidth Studios