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-11-2008, 04:04 AM
Vikram Kalsi
 
Posts: n/a
Default Source Code Help Needed

Hello,

I've been using Postgresql-8.0.1 (Release date: 2005-01-31) for my
research work and I guess I finally need some help with it...

I'm not trying to modify the existing functionality, but I want to add
few things. In particular, I'm calculating two new Cost values and I
need to use them while the query is executing. Please See code
snippets below-

1.) New Variables ADDED to src/include/nodes/plannodes.h
typedef struct Plan
{
Cost hutz_tbl_benefit; /* Benefit for TableAccess */
Cost hutz_idx_benefit; /* Benefit for IndexScan */
}


2.) New Variables ADDED to src/include/nodes/relation.h
typedef struct Plan
{
Cost hutz_tbl_benefit; /* Benefit for TableAccess */
Cost hutz_idx_benefit; /* Benefit for IndexScan */
}


3.) ADDITIONS to costsize.c

void cost_seqscan(Path *path, Query *root,
RelOptInfo *baserel)
{
path->hutz_tbl_benefit = xxxxx;
path->hutz_idx_benefit = xxxxx;
}


void cost_index(Path *path, Query *root, RelOptInfo *baserel,
IndexOptInfo *index, List *indexQuals, bool is_injoin)
{
path->hutz_tbl_benefit = xxxxx;
path->hutz_idx_benefit = xxxxx;
}


However, after these modifications the server process crashes on
running a Join query like
"select s_suppkey,c_custkey from supplier,customer where s_suppkey>125
and s_suppkey<128 and c_custkey>100 and c_custkey<103 and
c_custkey=s_suppkey"

But, this query runs fine "select s_suppkey from supplier where
s_suppkey>125 and s_suppkey<128"

I'm tracing the point at which the process crashes and at this point
it seems to inside
src/backend/optimizer/path/joinrels.c>>make_rels_by_joins()

So, my question is, after adding the two new variables what other
modifications do I need to make for code to work, And later on, what
changes are reqd so that I can access these variables while executing
the Query Plan in lets say ExecutePlan() and its sub-functions like
ExecProcNode()...

Thanks to everybody on this group,
-Vikram Kalsi
MSEE PennStateUniv

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 04:04 AM
Tom Lane
 
Posts: n/a
Default Re: Source Code Help Needed

Vikram Kalsi <vikramkalsi@gmail.com> writes:
> 1.) New Variables ADDED to src/include/nodes/plannodes.h
> 2.) New Variables ADDED to src/include/nodes/relation.h
> ...
> However, after these modifications the server process crashes on
> running a Join query like
> "select s_suppkey,c_custkey from supplier,customer where s_suppkey>125
> and s_suppkey<128 and c_custkey>100 and c_custkey<103 and
> c_custkey=s_suppkey"


Did you do a full recompile (make clean and rebuild) after modifying
these widely-known structures?

Unless you configured with --enable-depend, you can't expect that plain
"make" will recompile everything that needs recompiled.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 04:04 AM
Vikram Kalsi
 
Posts: n/a
Default Re: Source Code Help Needed

Thanks Tom, that solved it...I added the new variables one at a time
and did do a "make clean" on the first occasion but I must have
forgotten to do it the second time...

I have another question-
The new variables that I've added to Plan and Path i.e.
hutz_tbl_benefit and hutz_idx_benefit are being assigned values inside
cost_seqscan() and cost_index() in costsize.c and this is done
alongside startup_cost and total_cost.

But, when I read the value of hutz_tbl_benefit and hutz_idx_benefit
inside pg_plan_query() or later at the execution stage inside
ExecProcNode(), the value is absent, but startup_cost and total_cost
retain their values.

So, I suppose that during the query planning and optimization stage,
the value of the original variables in the plan are somehow copied to
the plan which is finally returned inside pg_plan_query().

Could somebody direct me to the appropriate code/function(s) which
does this copying so that I can add hutz_tbl_benefit and
hutz_idx_benefit to that as well.

Thanks in anticipation,
Regards,





On 5/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Vikram Kalsi <vikramkalsi@gmail.com> writes:
> > 1.) New Variables ADDED to src/include/nodes/plannodes.h
> > 2.) New Variables ADDED to src/include/nodes/relation.h
> > ...
> > However, after these modifications the server process crashes on
> > running a Join query like
> > "select s_suppkey,c_custkey from supplier,customer where s_suppkey>125
> > and s_suppkey<128 and c_custkey>100 and c_custkey<103 and
> > c_custkey=s_suppkey"

>
> Did you do a full recompile (make clean and rebuild) after modifying
> these widely-known structures?
>
> Unless you configured with --enable-depend, you can't expect that plain
> "make" will recompile everything that needs recompiled.
>
> regards, tom lane
>


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 04:04 AM
Tom Lane
 
Posts: n/a
Default Re: Source Code Help Needed

Vikram Kalsi <vikramkalsi@gmail.com> writes:
> So, I suppose that during the query planning and optimization stage,
> the value of the original variables in the plan are somehow copied to
> the plan which is finally returned inside pg_plan_query().


Look in createplan.c --- there are a couple places in there you need to
fix.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 04:12 AM
Vikram Kalsi
 
Posts: n/a
Default Re: Google's Summer of Code ...

I am a MSEE student at Penn State (University Park), for the past few
months I have been working on modifying parts of PostgreSQL for my
research work. I doubt if my current work would serve any purpose for
pgsql since it is experimental and research oriented, but all the
same, I have gained familiarity with parts of pgsql. I'm interested in
Google's Summer of Code, but I would definitely need help, starting
with selection of an idea to work on. So, if anybody from PostgreSQL
would like to support this, then please get in touch with me as early
as possible.

By the way, I didn't see PostgreSQL in the list of Participating
Organizations on http://code.google.com/summerofcode.html?

Thanks and Regards,
-Vikram Kalsi
MSEE PennState
vzk101 at psu dot edu
www.personal.psu.edu/vzk101


On 5/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Vikram Kalsi <vikramkalsi@gmail.com> writes:
> > So, I suppose that during the query planning and optimization stage,
> > the value of the original variables in the plan are somehow copied to
> > the plan which is finally returned inside pg_plan_query().

>
> Look in createplan.c --- there are a couple places in there you need to
> fix.
>
> regards, tom lane
>


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 04:12 AM
Vikram Kalsi
 
Posts: n/a
Default Re: Source Code Help Needed

Tom, Thanks a ton again, and, here's another problem that has me really
puzzled-

I'm starting with a fresh install of pgsql-8.0.1, and make 3 changes-

1.) src/include/nodes/relation.h, Add a new Variable, hutz_idx_benefit to
IndexOptInfo

typedef struct IndexOptInfo
{..............
/* Per IndexScan benefit, More than 1 indexscan maybe used for 1 tablescan
ex. w/ OR */
Cost hutz_idx_benefit;
...............} IndexOptInfo;


2.) src/backend/optimizer/path/costsize.c, cost_index(), assign value to
index->hutz_idx_benefit

run_cost += indexTotalCost - indexStartupCost;
index->hutz_idx_benefit = run_cost;
elog(NOTICE,"cost_index():index->indexoid=%u index->hutz_idx_benefit=%.2f",
index->indexoid, index->hutz_idx_benefit);


3.) src/backend/optimizer/path/orindxpath.c, best_or_subclause_indexes(),
Read the value(s) of index->indexoid and index->hutz_idx_benefit

/* Gather info for each OR subclause */
foreach(slist, subclauses)
{...................
infos = lappend(infos, best_indexinfo);
....................}

/* DEBUG */
ListCell *l;
int count=0;
foreach(l, infos)
{
IndexOptInfo *index = (IndexOptInfo *) lfirst(l);
elog(NOTICE,"best_or_subclause_indexes():infos c=%i: indexoid=%u
hutz_idx_benefit=%.2f", count, index->indexoid, index->hutz_idx_benefit);
count++;
}
....................
pathnode->indexinfo = infos; /* indexinfo' is a list of IndexOptInfo nodes,
one per scan to be performed */


So, basically I have added a new variable alongside indexoid which is the
run_cost of one of the index scans if there are multiple index scans such as
in the case of OR subclauses for 1 table.
Now, I do a complete build and run two queries with OR subclauses as
follows-

tpcd=# select s_suppkey from supplier where (s_suppkey>125 and
s_suppkey<128) or (s_suppkey>175 and s_suppkey<185) or (s_suppkey>200 and
s_suppkey<215);
NOTICE: cost_index():index->indexoid=186970 index->hutz_idx_benefit=2.02
NOTICE: cost_index():index->indexoid=186970 index->hutz_idx_benefit=2.06
NOTICE: cost_index():index->indexoid=186970 index->hutz_idx_benefit=2.09
NOTICE: best_or_subclause_indexes():infos c=0: indexoid=186970
hutz_idx_benefit=2.09
NOTICE: best_or_subclause_indexes():infos c=1: indexoid=186970
hutz_idx_benefit=2.09
NOTICE: best_or_subclause_indexes():infos c=2: indexoid=186970
hutz_idx_benefit=2.09

On the second occasion, I change the order of the OR subclauses...

tpcd=# select s_suppkey from supplier where (s_suppkey>200 and
s_suppkey<215) or (s_suppkey>175 and s_suppkey<185) or (s_suppkey>125 and
s_suppkey<128);
NOTICE: cost_index():index->indexoid=186970 index->hutz_idx_benefit=2.09
NOTICE: cost_index():index->indexoid=186970 index->hutz_idx_benefit=2.06
NOTICE: cost_index():index->indexoid=186970 index->hutz_idx_benefit=2.02
NOTICE: best_or_subclause_indexes():infos c=0: indexoid=186970
hutz_idx_benefit=2.02
NOTICE: best_or_subclause_indexes():infos c=1: indexoid=186970
hutz_idx_benefit=2.02
NOTICE: best_or_subclause_indexes():infos c=2: indexoid=186970
hutz_idx_benefit=2.02


From the output, it can be seen that when I try to read the value(s), the
last value is stored in all the positions of the List "infos" which is later
assigned to "(IndexPath) pathnode->indexinfo" which is a List of
"IndexOptInfo" nodes, one per scan to be performed. Actually, it seems all
the pointers in the List "indexinfo" or "infos" are pointing to the same
object.

So,
Ques 1) Is my assumption correct that IndexPath->indexinfo should contain
all distinct IndexOptInfo structs with one for each of the scans to be
performed? If not, then why do we have multiple pointers to the same object?

(Ques 2) How can this be fixed? Is this a bug or something else?

(Ques 3) Is this a problem in other areas as well, for example the following
query doesn't give the expected values as well-
select s_suppkey, c_custkey from supplier, customer where s_suppkey>125 and
s_suppkey<128 and c_custkey>125 and c_custkey<135 and c_custkey=s_suppkey;

I appreciate all the help of this group,
Thanks,


On 5/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Vikram Kalsi <vikramkalsi@gmail.com> writes:
> > So, I suppose that during the query planning and optimization stage,
> > the value of the original variables in the plan are somehow copied to
> > the plan which is finally returned inside pg_plan_query().

>
> Look in createplan.c --- there are a couple places in there you need to
> fix.
>
> regards, tom lane
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 04:12 AM
Robert Treat
 
Posts: n/a
Default Re: Google's Summer of Code ...

On Thursday 02 June 2005 18:52, Vikram Kalsi wrote:
> I am a MSEE student at Penn State (University Park), for the past few
> months I have been working on modifying parts of PostgreSQL for my
> research work. I doubt if my current work would serve any purpose for
> pgsql since it is experimental and research oriented, but all the
> same, I have gained familiarity with parts of pgsql. I'm interested in
> Google's Summer of Code, but I would definitely need help, starting
> with selection of an idea to work on. So, if anybody from PostgreSQL
> would like to support this, then please get in touch with me as early
> as possible.


I think the easyist thing is to look over the TODO list and see if there are 1
or more items that you might be interested in working on, and then either
mentioning them here or submitting them to google.

>
> By the way, I didn't see PostgreSQL in the list of Participating
> Organizations on http://code.google.com/summerofcode.html?
>


Marc has contacted google with intentions of joining that list, I would guess
the more people who submit postgresql related proposals, the more likely it
would be that we end up joining.

> Thanks and Regards,
> -Vikram Kalsi
> MSEE PennState
> vzk101 at psu dot edu
> www.personal.psu.edu/vzk101
>
> On 5/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > Vikram Kalsi <vikramkalsi@gmail.com> writes:
> > > So, I suppose that during the query planning and optimization stage,
> > > the value of the original variables in the plan are somehow copied to
> > > the plan which is finally returned inside pg_plan_query().

> >
> > Look in createplan.c --- there are a couple places in there you need to
> > fix.
> >
> > regards, tom lane

>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match


--
Robert Treat
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 04:12 AM
Tom Lane
 
Posts: n/a
Default Re: Source Code Help Needed

Vikram Kalsi <vikramkalsi@gmail.com> writes:
> ...
> tpcd=# select s_suppkey from supplier where (s_suppkey>125 and
> s_suppkey<128) or (s_suppkey>175 and s_suppkey<185) or (s_suppkey>200 and
> s_suppkey<215);
> ...
> Actually, it seems all
> the pointers in the List "indexinfo" or "infos" are pointing to the same
> object.


Given that query, it's not too surprising that the only relevant index
for all the OR clauses would be the one on s_suppkey ... if you want to
look at *all* the indexes on the relation, you need to scan the parent
RelOptInfo's indexlist.

You didn't say what it was you hoped to accomplish, but perhaps the
technique requires a more complicated query to be of any use?

BTW, best_or_subclause_indexes (and indeed most of orindxpath.c) is
gone in CVS tip; all that code has been rewritten for 8.1.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

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 11:17 AM.


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 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694