Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:48 PM
Dimitri Fontaine
 
Posts: n/a
Default GiST opclass and varlena

Hi,

I'm trying to code a GiST opclass to index prefix searches (select ... fromt
where t.prefix @> query), now using a prefix_range datatype. This datatype is
a varlena one, and storing it to disk and indexing it with BTrees work ok,
but I'm failing to have my GiST opclass working, here's the problem:

postgres=# create index idx_prefix on ranges using gist(prefix
gist_prefix_range_ops);
NOTICE: gpr_picksplit(): entryvec->n= 234 maxoff= 232 l= 176 r= 56 l+r= 232
unionL='01[0-7]' unionR='01[4-7]'
NOTICE: gpr_picksplit(): v->spl_ldatum='01[0-7]' v->spl_rdatum='01[4-7]'
ERROR: invalid memory alloc request size 3049878020

The code is available at pgfoundry here:
http://cvs.pgfoundry.org/cgi-bin/cvs...prefix/prefix/

The previous support for prefixes as text is still there (but will get
deprecated soon --- or so I hope), and the new datatype and its usage not
well commented nor documented currenlty. If this show up as a requirement to
get your attention, please state it and I'll work on documenting prefix_range
first.

I'm looking for some help on how to resolve the shown index creation problem,
which I think is related to how I give data to GiST in its spl_ldatum and
spl_rdatum from the user defined picksplit() method, lines 1101 and 1102 in
prefix.c (version 1.26).

Regards,
--
dim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBH6SRplBXRlnbh1bkRAuGWAKC9cnM7zNQq/5fRClZPSCjAiYUN+QCglf3Z
GuIEVYi5p2J/fqYRVPTMCbw=
=qB7V
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 10:48 PM
Dragan Zubac
 
Posts: n/a
Default Re: GiST opclass and varlena

Hello

Not so familiar with all this math ,but here's my solution,which I
must admit keep things going at the moment:

db=> \d prefix
Table "public.prefix"
Column | Type | Modifiers
----------+---------+-----------------------------------------------------
id | bigint | not null default nextval('prefix_id_seq'::regclass)
prefix | text |
operator | integer |
Indexes:
"prefix_pkey" PRIMARY KEY, btree (id)
"prefix_index" UNIQUE, btree (prefix)


and we're using a procedure to match prefices (longest prefix
match),with simething like:

....

-- CHECK PREFIX START

while tmp_length <= char_length(d_number) loop

-- take the number and try to find it in prefix table
-- if not found,decrease it by removing last number
-- and try again

tmp_dest_number := substring (d_number from 1 for tmp_length);

select into operator_temp operator from prefix
where prefix=tmp_dest_number;

if not found then
tmp_length := tmp_length + 1;
else

-- if we have a match with some prefix
-- take the operator from that row

operatorfound := true;
operator_out := operator_temp;
exit;
end if;

end loop;

-- CHECK PREFIX STOP

.....

only 'semantic' problem You might have with this approach is that number
is like 16511xxxxx,which belongs to some Hawaii island operator ,but
the problem is that all You have in Your prefix table is 16xxxxxx,which
You mark to belong to operator USA Something. In that case,Your system
will think of 16511xxxxxx number as it belongs to USA Something operator
and not Hawaii island operator Only solution to this is to always
have up-to-date prefix table,and populate it even with the prefices Your
system does not support,because Your system then reject that number and
it will have a good/precise reason why he did it

Some poorly measurement showed some 60-80 matching/sec with this
algorithm of matching prefices and a couple of concurrent database
connections.

Sincerely

Dragan

Dimitri Fontaine wrote:
> Hi,
>
> I'm trying to code a GiST opclass to index prefix searches (select ... from t
> where t.prefix @> query), now using a prefix_range datatype. This datatype is
> a varlena one, and storing it to disk and indexing it with BTrees work ok,
> but I'm failing to have my GiST opclass working, here's the problem:
>
> postgres=# create index idx_prefix on ranges using gist(prefix
> gist_prefix_range_ops);
> NOTICE: gpr_picksplit(): entryvec->n= 234 maxoff= 232 l= 176 r= 56 l+r= 232
> unionL='01[0-7]' unionR='01[4-7]'
> NOTICE: gpr_picksplit(): v->spl_ldatum='01[0-7]' v->spl_rdatum='01[4-7]'
> ERROR: invalid memory alloc request size 3049878020
>
> The code is available at pgfoundry here:
> http://cvs.pgfoundry.org/cgi-bin/cvs...prefix/prefix/
>
> The previous support for prefixes as text is still there (but will get
> deprecated soon --- or so I hope), and the new datatype and its usage not
> well commented nor documented currenlty. If this show up as a requirement to
> get your attention, please state it and I'll work on documenting prefix_range
> first.
>
> I'm looking for some help on how to resolve the shown index creation problem,
> which I think is related to how I give data to GiST in its spl_ldatum and
> spl_rdatum from the user defined picksplit() method, lines 1101 and 1102 in
> prefix.c (version 1.26).
>
> Regards,
>



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:48 PM
Dimitri Fontaine
 
Posts: n/a
Default Re: GiST opclass and varlena

Le Tuesday 25 March 2008 17:57:11 Dragan Zubac, vous avez écrit*:
> and we're using a procedure to match prefices (longest prefix
> match),with simething like:
>
> while tmp_length <= char_length(d_number) loop
>
> -- take the number and try to find it in prefix table
> -- if not found,decrease it by removing last number
> -- and try again

[...]
> Some poorly measurement showed some 60-80 matching/sec with this
> algorithm of matching prefices and a couple of concurrent database
> connections.


With the GiST index support we're hoping to get millisecond response time
order (that mean something like 1000 matching per sec, best case), and witha
query that simple :
SELECT operator
FROM prefix
WHERE prefix @> '16511xxxxxx'
ORDER BY len(prefix) DESC
LIMIT 1;

For this you have to create a dedicated index, first version of the code has
this version:
http://prefix.projects.postgresql.org/README.html
CREATE INDEX idx_prefix ON prefix USING GIST(prefix gist_prefix_ops);

New version I'm trying to make work looks like this:
CREATE TABLE prefix(id serial, prefix prefix_range, operator integer);
CREATE INDEX idx_prefix ON prefix USING GIST(prefix gist_prefix_range_ops);

Former usage shows performance of 2 to 5 ms answer time on lower setups
(meaning sth like 200 reqs/s already), latter one is aiming at 1000 req/s as
said before, but does not work at all at the moment... The goal is to be able
to use the search from an AFTER INSERT TRIGGER to materialize some calling
stats and prices, etc. So it has to be that fast.

Please consider trying the code if you're interrested, it's been tested with
PostgreSQL versions 8.2 and 8.3, and former version is working fine with text
type prefixes, and should offer you some speedups already.

Hope this helps clarifying the goals and context,
--
dim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBH6V/HlBXRlnbh1bkRAn91AKCQ5nds+XchHorrGbYy5ujco7nHZACfR 8+Y
AYoIbntbzIof7MH9pkj4LUo=
=eXf2
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 10:49 PM
Dimitri Fontaine
 
Posts: n/a
Default Re: GiST opclass and varlena

Le mardi 25 mars 2008, Dimitri Fontaine a écritÂ*:
> postgres=# create index idx_prefix on ranges using gist(prefix
> gist_prefix_range_ops);
> NOTICE: gpr_picksplit(): entryvec->n= 234 maxoff= 232 l= 176 r= 56 l+r=
> 232 unionL='01[0-7]' unionR='01[4-7]'
> NOTICE: gpr_picksplit(): v->spl_ldatum='01[0-7]' v->spl_rdatum='01[4-7]'
> ERROR: invalid memory alloc request size 3049878020


My previous tests were only done with REL8_2_STABLE cvs branch, I just redone
some tests with REL8_3_STABLE and got no error. The index is still buggy, in
the sense some requests returns different results with or without it
(enable_seqscan).

I've received some help on testing it too, and it seems the behavior is also
dependent on the architecture used. I'm using 32 bits linux arch, tests in 64
bit arch showed no error.

> The code is available at pgfoundry here:
> http://cvs.pgfoundry.org/cgi-bin/cvs...prefix/prefix/


It still is
The easy way to test it is:

create table prefixes (
prefix text primary key,
name text not null,
shortname text,
state char default 'S',

check( state in ('S', 'R') )
);
comment on column prefixes.state is 'S: - R: reserved';

\copy prefixes from 'prefixes.fr.csv' with delimiter ; csv quote '"'

create table ranges as
select prefix:refix_range, name, shortname, state from prefixes ;

create index idx_prefix on ranges using gist(prefix gist_prefix_range_ops);

Then enable_seqscan to on or off, and queries such as
select * from ranges where prefix @> '0100101234';
select * from ranges where prefix @> '0146640123';

On my 8.3 testing, the former query gives the same result with or without
using the GiST index, the latter doesn't.

Regards,
--
dim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBH82EXlBXRlnbh1bkRAs5vAKCyI4DmB1TWE6YQ2BbnSi HdpP0TygCgz3Zg
RTwecqEEK922Yn2jhf0vK2k=
=p9jI
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 10:51 PM
Dimitri Fontaine
 
Posts: n/a
Default Re: GiST opclass and varlena

I guess I'll keep talking to myself, but...

Le mercredi 02 avril 2008, Dimitri Fontaine a écritÂ*:
> My previous tests were only done with REL8_2_STABLE cvs branch, I just
> redone some tests with REL8_3_STABLE and got no error. The index is still
> buggy, in the sense some requests returns different results with or without
> it (enable_seqscan).


It turned around the error was related to the definition of my gpr_penalty()
function, which I wanted to expose as the GiST "internal" and a SQL callable
one too (for debugging and tests purpose). I forgot to define the internal
one in the prefix.c side of things, got no complaint whatsover (nor at
compile time neither at prefix.sql installation time) but garbage as data in
__pr_penalty() function (not respecting GiST calling conventions).

I guess the 8.2 invalid memory alloc request size ERROR was related to the
same pilot error, as it's now gone too.

Now this problem is overcome and the codes allows me again to create index and
use them in queries both in 8.2 and 8.3, but there's still DEBUG ongoing.
I've augmented the README for interested people to have more information:
http://prefix.projects.postgresql.org/README.html

Regards,
--
dim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBH/iH2lBXRlnbh1bkRAgW2AJ9u9sl43O3OYDShl2KtXVbfK05tdwC cDKzN
ESeiBbO3qP70vLIVGxWM2Ng=
=VTgK
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-15-2008, 10:51 PM
Gregory Stark
 
Posts: n/a
Default Re: GiST opclass and varlena

"Dimitri Fontaine" <dfontaine@hi-media.com> writes:

> It turned around the error was related to the definition of my gpr_penalty()
> function, which I wanted to expose as the GiST "internal" and a SQL callable
> one too (for debugging and tests purpose). I forgot to define the internal
> one in the prefix.c side of things, got no complaint whatsover (nor at
> compile time neither at prefix.sql installation time) but garbage as data in
> __pr_penalty() function (not respecting GiST calling conventions).


I'm getting interested now. How was __pr_penalty defined? What was the
declaration you were missing in prefix.c?

Was it specifically related to a varlena or was it a char or something like
that?

And was it something gcc -Wall was warning about or somehow was it slipping
by?

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's PostGIS support!

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-15-2008, 10:51 PM
Dimitri Fontaine
 
Posts: n/a
Default Re: GiST opclass and varlena

Le jeudi 10 avril 2008, Gregory Stark a écrit*:
> I'm getting interested now. How was __pr_penalty defined? What was the
> declaration you were missing in prefix.c?


In fact __pr_penalty is the internal code called from both the SQL callable
functions (and some other calling sites). The problem was that I missed some
SQL callable definitions and it got called with internal parameters instead
of the prefix_range * it expects.

Details:
http://cvs.pgfoundry.org/cgi-bin/cvs...1=1.33&r2=1.32
http://cvs.pgfoundry.org/cgi-bin/cvs...1=1.15&r2=1.14

> Was it specifically related to a varlena or was it a char or something like
> that?


The datatype I'm playing with is prefix_range and is used as a varlena:
typedef struct {
char first;
char last;
char prefix[1]; /* this is a varlena structure, data follows */
} prefix_range;

Then have a look at make_varlena() function and those macros:

#define DatumGetPrefixRange(X) ((prefix_range *)
PREFIX_VARDATA(DatumGetPointer(X)) )
#define PrefixRangeGetDatum(X) PointerGetDatum(make_varlena(X))
#define PG_GETARG_PREFIX_RANGE_P(n)
DatumGetPrefixRange(PG_DETOAST_DATUM(PG_GETARG_DAT UM(n)))
#define PG_RETURN_PREFIX_RANGE_P(x) return PrefixRangeGetDatum(x)

> And was it something gcc -Wall was warning about or somehow was it slipping
> by?


I didn't see any errors from gcc nor from PostgreSQL. I just was using the
following function definition for the two following SQL functions:

PG_FUNCTION_INFO_V1(pr_penalty);
Datum
pr_penalty(PG_FUNCTION_ARGS)
{
float penalty = __pr_penalty(PG_GETARG_PREFIX_RANGE_P(0),
PG_GETARG_PREFIX_RANGE_P(1));
PG_RETURN_FLOAT4(penalty);
}

CREATE OR REPLACE FUNCTION gpr_penalty(internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C' STRICT;

CREATE OR REPLACE FUNCTION gpr_penalty(prefix_range, prefix_range)
RETURNS float4
AS 'MODULE_PATHNAME'
LANGUAGE 'C' STRICT;

This last one is now pr_penalty and as a matching function defined in the
prefix.c file, which was not the case when all was wrong. And of course the
gpr_penalty code has been rewrote to be correct WRT its arguments processing.

Sorry to be using CVS at pgfoundry, if it was something more elaborate a
revision id could get you easily to the buggy version, here you'll have to
play some cvs game to get the version before the commit with this message, if
you wanted to try the bug yourself:
Respect GiST calling conventions for gpr_penalty()

Hope this helps, regards,
--
dim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBH/jSjlBXRlnbh1bkRAr9OAKCqtt+WmcrTJiDrvDGkhWLqMrpm8wC dGDxX
zPSgNVk1d4g+IkMarKpW9Lw=
=dcQU
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-24-2008, 06:13 PM
Dimitri Fontaine
 
Posts: n/a
Default Re: GiST opclass and varlena

Hi all,

The first version of prefix code is now released at pgfoundry, last bug
squashed by Jordan, who did his own prefix gist opclass implementation before
I did, but didn't publish at this time. The plan is to integrate is work into
the prefix solution, as his lookups are faster than mine, and the code base
simpler but limited to varchar(15).

You can get the prefix_range datatype and prefix search GiST opclass here:
http://cvs.pgfoundry.org/cgi-bin/cvs...prefix/prefix/
http://prefix.projects.postgresql.org/README.html
http://pgfoundry.org/frs/?group_id=1000352

Le mardi 25 mars 2008, Dragan Zubac a écrit*:
> Some poorly measurement showed some 60-80 matching/sec with this
> algorithm of matching prefices and a couple of concurrent database
> connections.


On a workstation class hardware with a 11966 rows prefix table, 25000 random
10 digit numbers where matched in less than 5s, having an average lookup time
of about 0.2ms, or 5000 matches per second.
http://prefix.projects.postgresql.org/TESTS.html

If you need some speedups on prefix matching but are not willing to install
any C-code additional module, please check this blog entry:
http://www.depesz.com/index.php/2008...ongest-prefix/

The cvs and tarball version of prefix have been tested on PostgreSQL versions
8.2 and 8.3, figures from tests were obtained with 8.3, and debian packages
are available for 8.3 only at the moment.

Regards,
--
dim

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBIDeSulBXRlnbh1bkRAj+mAKCnc6m6RZ2waSVSn2T6Dk 0fAD21NwCeL3NQ
t889uU+DgXzlUJzYpaR4pWE=
=93Eb
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:31 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656