Commit 798917c
authored
VLE cache + performance improvements (#2376)
VLE cache + perf: version counter, thin entries, variadic elimination,
edge cleanup list removal
Replace snapshot-based VLE cache invalidation with per-graph version
counters and add performance optimizations for VLE traversal.
Cache invalidation:
- Add DSM (PG 17+) and shmem (PG <17) per-graph monotonic version
counters for cross-backend cache invalidation
- Replace snapshot xmin/xmax/curcid comparison with version counter
check in is_ggctx_invalid(), with snapshot fallback for safety
- Add executor hooks in CREATE/DELETE/SET/MERGE to increment the
graph version counter on mutations
- Add SQL trigger function (age_invalidate_graph_cache) for catching
SQL-level mutations (INSERT/UPDATE/DELETE/TRUNCATE)
- Auto-install trigger on new label tables via label_commands.c
with LookupFuncName check for backward compatibility
- Add TRUNCATE interception in ProcessUtility hook (ag_catalog.c)
- Add shmem_request/startup hooks for PG <17 (age.c)
- Use search_label_relation_cache() in get_graph_oid_for_table()
for fast label-to-graph lookup instead of catalog table scan
Thin entries (lazy property fetch):
- Replace Datum edge_properties/vertex_properties with 6-byte
ItemPointerData TID in vertex_entry and edge_entry
- Add get_vertex_entry_properties() and get_edge_entry_properties()
that do heap_fetch via stored TID on demand
- Add is_an_edge_match() fast path: skip property access entirely
for label-only VLE patterns (the common case)
Edge cleanup list removal:
- Remove ggctx->edges linked list from GRAPH_global_context. With
thin entries, edge_entry has no palloc'd sub-structures to free
(TIDs are inline). The cleanup list existed to pfree datumCopy'd
edge_properties Datums, which no longer exist. hash_destroy()
handles all edge hash table memory. Saves ~5.6 GB at SF10.
Performance optimizations:
- Reduce VERTEX/EDGE_HTAB_INITIAL_SIZE from 1,000,000 to 10,000.
PG dynahash grows automatically; large initial size wastes memory.
- Eliminate extract_variadic_args in age_match_vle_terminal_edge:
direct PG_GETARG_DATUM + cached arg types via fn_extra
- Eliminate extract_variadic_args in age_match_vle_edge_to_id_qual:
same pattern
- Add agtype_access_operator 2-arg fast path: bypasses
extract_variadic_args_min for the common property access case
- Add age_tointeger 1-arg fast path: bypasses extract_variadic_args
with cached arg type
- Add GraphIdStack (flat array-based) DFS stacks replacing
ListGraphId linked-list stacks for push/pop without palloc/pfree
Upgrade script:
- Add trigger installation on pre-existing label tables during
extension upgrade via DO block in age--1.7.0--y.y.y.sql. Tables
created after upgrade get triggers automatically via label_commands.c.
Regression tests:
- Add VLE cache invalidation tests (CREATE, DELETE, SET mutations)
- Add thin entry edge property fetch tests (RETURN p, UNWIND)
- Add direct SQL trigger tests (INSERT, UPDATE, DELETE, TRUNCATE on
label tables with VLE cache invalidation verification)
All 32 regression tests pass.
SF3 Benchmarks (9.3M vertices, 52.7M edges, warm cache, median):
Total IC1-IC12: 1,530s -> 1,159s (-24.3%, 371s saved)
VLE-heavy queries:
IC3 (KNOWS*1..2 + 2 countries): 34.9s -> 20.7s (-40.6%)
IC5 (forum members, KNOWS*1..2): 46.2s -> 29.9s (-35.4%)
IC6 (tag co-occurrence, KNOWS*1..2): 28.2s -> 19.2s (-31.8%)
IC9 (recent messages, KNOWS*1..2): 86.0s -> 60.4s (-29.7%)
IC11 (KNOWS*1..2 + WORK_AT): 18.7s -> 11.0s (-41.5%)
IC1 (KNOWS*1..3 + profile): 1269.4s -> 974.9s (-23.2%)
Short Reads (IS1-IS7): No meaningful change -- non-VLE queries,
sub-millisecond to sub-second. Within run-to-run variance.
Updates (IU1-IU8, SF3, median, 50 ops each):
IU2 (Like Post): 99.5ms -> 6.3ms (-93.6%)
IU3 (Like Comment): 318.3ms -> 5.7ms (-98.2%)
IU7 (Add Comment): 344.4ms -> 11.3ms (-96.7%)
IU5 (Forum Member): 12.3ms -> 5.9ms (-52.0%)
Version counter eliminates redundant VLE cache rebuilds on mutations.
Previously, every INSERT/UPDATE/DELETE invalidated the cache via
snapshot comparison, forcing a full rebuild on the next VLE query.
Now, mutations just bump a counter; rebuild only occurs when VLE
actually runs and finds the counter changed.
Graph cache memory (SF3, calculated):
Total: ~15.7 GB -> ~8.7 GB (-45%, 7.0 GB saved)
Thin entries (TID replaces datumCopy'd properties): -5.3 GB
Edge cleanup list removal (no longer needed): -1.7 GB
Co-authored-by: Claude Opus <noreply@anthropic.com>
modified: age--1.7.0--y.y.y.sql
modified: regress/expected/age_global_graph.out
modified: regress/sql/age_global_graph.sql
modified: sql/age_main.sql
modified: src/backend/age.c
modified: src/backend/catalog/ag_catalog.c
modified: src/backend/commands/label_commands.c
modified: src/backend/executor/cypher_create.c
modified: src/backend/executor/cypher_delete.c
modified: src/backend/executor/cypher_merge.c
modified: src/backend/executor/cypher_set.c
modified: src/backend/utils/adt/age_global_graph.c
modified: src/backend/utils/adt/age_graphid_ds.c
modified: src/backend/utils/adt/age_vle.c
modified: src/backend/utils/adt/agtype.c
modified: src/include/utils/age_global_graph.h
modified: src/include/utils/age_graphid_ds.h1 parent ee25e2a commit 798917c
17 files changed
Lines changed: 1629 additions & 266 deletions
File tree
- regress
- expected
- sql
- sql
- src
- backend
- catalog
- commands
- executor
- utils/adt
- include/utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 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 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
416 | 704 | | |
417 | 705 | | |
418 | 706 | | |
| |||
0 commit comments