pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedGIN index
4+ messages / 3 participants
[nested] [flat]
* GIN index
@ 2021-10-11 08:00 huangning290@yahoo.com <huangning290@yahoo.com>
0 siblings, 1 reply; 4+ messages in thread
From: huangning290@yahoo.com @ 2021-10-11 08:00 UTC (permalink / raw)
To: pgsql-general
Hi
I created a new data type, and then I wanted to create a GIN index for it, but when I created the index, the program would crash 。 The version of postgresql is 9.6。
The following is part of the code, and I also refer to the code of intarray.
```sqlCREATE OR REPLACE FUNCTION geomgrid_in(cstring) RETURNS geomgrid AS '$libdir/module-1.0','geomgrid_in' LANGUAGE 'c' NOT FENCED IMMUTABLE STRICT ;
CREATE OR REPLACE FUNCTION geomgrid_out(geomgrid) RETURNS cstring AS '$libdir/module-1.0','geomgrid_out' LANGUAGE 'c' NOT FENCED IMMUTABLE STRICT ;
CREATE OR REPLACE FUNCTION geomgrid_recv(internal) RETURNS geomgrid AS '$libdir/module-1.0','geomgrid_recv' LANGUAGE 'c' NOT FENCED IMMUTABLE STRICT ;
CREATE OR REPLACE FUNCTION geomgrid_send(geomgrid) RETURNS bytea AS '$libdir/module-1.0','geomgrid_send' LANGUAGE 'c' NOT FENCED IMMUTABLE STRICT ;
CREATE TYPE geomgrid( internallength = 8, input = geomgrid_in, output = geomgrid_out, send = geomgrid_send, receive = geomgrid_recv, alignment = double, PASSEDBYVALUE = true, storage = plain);
CREATE OPERATOR CLASS gin_grid_opsDEFAULT FOR TYPE _geomgrid USING ginAS OPERATOR 3 &&, OPERATOR 6 = (anyarray, anyarray), OPERATOR 7 @>, OPERATOR 8 <@, FUNCTION 1 grid_cmp(geomgrid,geomgrid), FUNCTION 2 gridarray_extract (anyarray, internal, internal), FUNCTION 3 gridarray_queryextract (geomgrid, internal, int2, internal, internal, internal, internal),```
```cDatum geomgrid_in(PG_FUNCTION_ARGS){ char *input = PG_GETARG_CSTRING(0); int len = strlen(input); if (len != 16) PG_RETURN_NULL();
char *data = palloc(len / 2 ); for (int i = 0, j = 7; i < len; i += 2, j--) { data[j] = Char2Hex(input + i); } int64_t* return_data = (int64_t*)data; PG_RETURN_INT64(*return_data);}
Datum geomgrid_out(PG_FUNCTION_ARGS){ int64_t out_data = PG_GETARG_INT64(0); char* buf_data = (char*)(&out_data);
unsigned char dst[2] = {0};
char *result = palloc(16 + 1); memset(result, 0, 16 + 1);
for (int i = 7, j = 0; i >= 0; i--, j++) { Hex2Char((unsigned char)buf_data[i], dst); result[j * 2 + 1] = dst[0]; result[j * 2] = dst[1]; } PG_RETURN_CSTRING(result);}```
```cDatum gridarray_extract(PG_FUNCTION_ARGS){ ArrayType *array = PG_GETARG_ARRAYTYPE_P_COPY(0); int size = VARSIZE(array); int32 *nkeys = (int32 *)PG_GETARG_POINTER(1); bool **nullFlags = (bool **)PG_GETARG_POINTER(2);
if (array == NULL || nkeys == NULL || nullFlags == NULL) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("Invalid arguments for function gridarray_extract")));
int16 elmlen; bool elmbyval = false; char elmalign; Datum *elems = NULL; bool *nulls = NULL; int nelems;
get_typlenbyvalalign(ARR_ELEMTYPE(array), &elmlen, &elmbyval, &elmalign);
deconstruct_array(array, ARR_ELEMTYPE(array), elmlen, elmbyval, elmalign, &elems, &nulls, &nelems);
*nkeys = nelems; *nullFlags = nulls; PG_RETURN_POINTER(elems);}```
then i debug it . this is my debug info.
thank you!
Attachments:
f71916d7254ff236aef8f26efffcfb3.png (image/png, 507.8K) download
view image
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: GIN index
@ 2021-10-13 21:19 Tomas Vondra <tomas.vondra@enterprisedb.com>
parent: huangning290@yahoo.com <huangning290@yahoo.com>
0 siblings, 0 replies; 4+ messages in thread
From: Tomas Vondra @ 2021-10-13 21:19 UTC (permalink / raw)
To: huangning290@yahoo.com <huangning290@yahoo.com>; pgsql-general
Hi,
Why exactly are you starting a new thread again, instead of continuing
in the thread you started a couple days ago?
A couple recommendations:
1) I find it unlikely you'll get a lot of help unless you provide a way
to reproduce the issue easily. That is, something people can build and
test on their own. Posting incomplete chunks of code means we'd have to
spend time filling in the gaps, etc. Sorry, not going to happen.
Create an extension that we can build/install easily, include a SQL
script reproducing the issue.
2) The code is incomplete, e.g. hex2char/char2hex are missing. And the
calls seems to be the other way around. I'd expect geomgrid_in to
transform hex string to binary, but it calls Char2Hex.
3) AFIAK there's nothing like CREATE FUNCTION ... NOT FENCED ..., so it
seems you're using some sort of fork. In that case you should probably
ask them.
4) Don't post backtraces as screenshots. Copy them as text, attach them
as a text file.
5) Continue in the thread you already started, otherwise it's impossible
to follow the discussion.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 4+ messages in thread
* GIN index
@ 2022-01-25 02:42 huangning290@yahoo.com <huangning290@yahoo.com>
0 siblings, 1 reply; 4+ messages in thread
From: huangning290@yahoo.com @ 2022-01-25 02:42 UTC (permalink / raw)
To: pgsql-general
Hi:I created a new variable-length data type, and now I want to create a GIN index for it. According to the rules of GIN index, I created three functions: extractValue, extractQuery, and compare. I made sure that the return value of the first two functions is the address of the array, but when using the index query, the GIN tuple data obtained by calling PG_GETARG_DATUM in the compare function is incorrect, and it is misplaced! In memory the size of the data header becomes something else, and the position of the first byte is not the header, it becomes the fourth byte. So there is a high probability that the function called is wrong or my return value is wrong when creating the index or the error is somewhere else?
regards!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: GIN index
@ 2022-01-25 15:33 Julien Rouhaud <rjuju123@gmail.com>
parent: huangning290@yahoo.com <huangning290@yahoo.com>
0 siblings, 0 replies; 4+ messages in thread
From: Julien Rouhaud @ 2022-01-25 15:33 UTC (permalink / raw)
To: huangning290@yahoo.com <huangning290@yahoo.com>; +Cc: pgsql-general
Hi,
On Tue, Jan 25, 2022 at 02:42:14AM +0000, huangning290@yahoo.com wrote:
> Hi:I created a new variable-length data type, and now I want to create a GIN
> index for it. According to the rules of GIN index, I created three functions:
> extractValue, extractQuery, and compare. I made sure that the return value of
> the first two functions is the address of the array, but when using the index
> query, the GIN tuple data obtained by calling PG_GETARG_DATUM in the compare
> function is incorrect, and it is misplaced! In memory the size of the data
> header becomes something else, and the position of the first byte is not the
> header, it becomes the fourth byte. So there is a high probability that the
> function called is wrong or my return value is wrong when creating the index
> or the error is somewhere else?
It's hard to have an opinion without seeing any code extract. Have you checked
contrib module for examples of other GIN opclasses, like pg_trgrm, or hstore
for varlena datatype with GIN support?
Note also that pgsql-hackers is probably a better mailing list for this kind of
questions.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2022-01-25 15:33 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 08:00 GIN index huangning290@yahoo.com <huangning290@yahoo.com>
2021-10-13 21:19 ` Tomas Vondra <tomas.vondra@enterprisedb.com>
2022-01-25 02:42 GIN index huangning290@yahoo.com <huangning290@yahoo.com>
2022-01-25 15:33 ` Julien Rouhaud <rjuju123@gmail.com>
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