From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: David Steele <david@pgmasters.net>
Cc: peter.eisentraut@2ndquadrant.com, PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: [PATCH] Generic type subscripting
Date: Thu, 30 Mar 2017 20:36:40 +0300
Message-ID: <91a90c4e-9e95-60be-d796-d319b640655c@postgrespro.ru> (raw)
In-Reply-To: <38e32275-91f2-61e9-24dd-57135a662c41@postgrespro.ru>
References: <CA+q6zcVovR+XY4mfk-7oNk-rF91gH0PebnNfuUjuuDsyHjOcVA@mail.gmail.com>
<20423.1489533013@sss.pgh.pa.us>
<393cd0ae-5b84-849e-fc73-7077470a009e@pgmasters.net>
<CA+q6zcUX=Om75kgZXkpYPhnwUCo4osFpzd83dKPzjSGfCmxEgA@mail.gmail.com>
<65df4a65-a9d8-3531-5baf-edb237771f0e@pgmasters.net>
<22355.1490369372@sss.pgh.pa.us>
<449f42b9-f338-9e45-cb33-3e15c7b547ad@postgrespro.ru>
<CA+q6zcWFLpEX6H1LOOKFJMAN+LB+mmEx=6Syd4WVioXkbXq32A@mail.gmail.com>
<c7cc0592-4c9b-699d-3b61-810804759de6@postgrespro.ru>
<CA+q6zcXQ9UO0_qGqoFgd_4ymKYxwr-3he+abEbnWaPk2nbmPVQ@mail.gmail.com>
<CA+q6zcXsonX+qLhf2crQgj14NzJmcibABhyVch1kjNtSL1+V1A@mail.gmail.com>
<38e32275-91f2-61e9-24dd-57135a662c41@postgrespro.ru>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 29.03.2017 20:14, Arthur Zakirov wrote:
>
> I wanted to implement subscripting for ltree or hstore extensions.
> Subscripting for ltree looks more interesting. Especially with slicing.
> But I haven't done it yet. I hope that I will implement it tomorrow.
>
ltree
-----
I've implemented fetching ltree elements using subscripting. But haven't
implemented assigning ltree elements yet. I'll send second patch after
implementing assigning.
Now you can execute the following query:
SELECT ('Top.Science.Astronomy.Astrophysics'::ltree)[1:2];
ltree
-------------
Top.Science
Comments
--------
But I've noticed about some points.
In array_subscript_parse() passed uninitialized values of "typesource"
and "typeneeded" variables for coerce_to_target_type().
> + typesource = exprType(assignExpr);
> + typesource = is_slice ? sbsref->refcontainertype : sbsref->refelemtype;
Here is the bug. Second variable should be "typeneeded". Moreover these
assignments should be moved up to first coerce_to_target_type() execution.
> + foreach(l, sbsref->reflowerindexpr)
> + {
> + List *expr_ai = (List *) lfirst(l);
> + A_Indices *ai = (A_Indices *) lfirst(list_tail(expr_ai));
> +
> + subexpr = (Node *) lfirst(list_head(expr_ai));
This code looks like a magic. This happens because of appending
A_Indeces to lowerIndexpr:
> - subexpr = NULL;
> + lowerIndexpr = lappend(lowerIndexpr, list_make2(subexpr, ai));
> }
And this A_Indeces used only when slicing is not used to make a constant
1. Maybe there are another way?
Also it would be better if "refevalfunc" and "refnestedfunc" had
pointers to functions not Oid type. Now you need to create "..._fetch"
and "..._assign" functions in catalog and in "..._parse" function you
need get their Oid using to_regproc() function.
Can we use IndexAmRoutine structure method, when you use only pointers
to necessary functions? You can see an example in blhandler() function
in blutils.c.
The last point is about the tutorial. As Tom pointed it is not useful
when the tutorial doesn't execute. It happens because there is not
"custom" type in subscripting.sql. Also it contradicts the README of
tutorials.
--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: a.zakirov@postgrespro.ru, 9erthalion6@gmail.com, tgl@sss.pgh.pa.us, david@pgmasters.net
Subject: Re: [PATCH] Generic type subscripting
In-Reply-To: <91a90c4e-9e95-60be-d796-d319b640655c@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox