Parallel not working

2022-05-17 Thread huangning...@yahoo.com
Hi:
I write a  C function, the function is as follows:
create function st_geosotgrid(geom geometry, level integer) returns geosotgrid[]
immutable
strict
parallel safe
language c
as
$$
begin
-- missing source code
end;
$$;




At the same time, I set the relevant parameters:
force_parallel_mode: offmax_parallel_maintenance_workers: 
4max_parallel_workers: 8max_parallel_workers_per_gather: 2max_worker_processes: 
8min_parallel_index_scan_size: 64min_parallel_table_scan_size: 
1024parallel_leader_participation: on
set parallel_setup_cost = 10;set parallel_tuple_cost = 0.001;

sql:
select st_geosotgrid(geom,20) from t_polygon_gis;

and the explain as follows:

Gather  (cost=10.00..5098.67 rows=20 width=32)  Workers Planned: 2  ->  
Parallel Seq Scan on t_polygon_gis  (cost=0.00..4888.67 rows=8 width=32)


when i explain analyze ,the parallel worker is suspend:




 I would like to know how can I get it to work properly?

Thank You!



GIN theory

2022-06-03 Thread huangning...@yahoo.com
Hi:
I want to know the time that create a gin index for a array, or some theory 
about gin index?

Thanks

create a new GIN index for my own type

2021-10-04 Thread huangning...@yahoo.com
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);}```
 Best Regards!

develop a extension with cpp?

2021-11-02 Thread huangning...@yahoo.com
Hi    if i can develop a extension with cpp language?















regards!

Re: develop a extension with cpp?

2021-11-03 Thread huangning...@yahoo.com
Thank you.  

On Wednesday, November 3, 2021, 06:20:18 AM GMT+8, Dmitry Igrishin 
 wrote:  
 
 вт, 2 нояб. 2021 г. в 20:12, huangning...@yahoo.com :
>
> Hi
>    if i can develop a extension with cpp language?
Sure, you can. Please, see example -- https://github.com/dmitigr/pgnso
  

GIN index

2022-01-25 Thread huangning...@yahoo.com
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!