* This function returns a list of collectionId of all the collections in given db * It also fills the "views" pointer with the number of views on the collection. */
| 604 | * It also fills the "views" pointer with the number of views on the collection. |
| 605 | */ |
| 606 | static List * |
| 607 | GetAllCollectionIdsInDb(Datum databaseNameDatum, int64 *views) |
| 608 | { |
| 609 | List *collectionIdsList = NIL; |
| 610 | const char *query = |
| 611 | FormatSqlQuery("SELECT * FROM %s.collections WHERE database_name = $1", |
| 612 | ApiCatalogSchemaName); |
| 613 | |
| 614 | int nargs = 1; |
| 615 | Oid argTypes[1] = { TEXTOID }; |
| 616 | Datum argValues[1] = { databaseNameDatum }; |
| 617 | |
| 618 | bool readOnly = true; |
| 619 | MemoryContext priorMemoryContext = CurrentMemoryContext; |
| 620 | |
| 621 | SPI_connect(); |
| 622 | |
| 623 | Portal statsPortal = SPI_cursor_open_with_args("workerDbStatsGetCollectionsInDb", |
| 624 | query, nargs, |
| 625 | argTypes, argValues, |
| 626 | NULL, readOnly, 0); |
| 627 | bool hasData = true; |
| 628 | while (hasData) |
| 629 | { |
| 630 | SPI_cursor_fetch(statsPortal, true, INT_MAX); |
| 631 | |
| 632 | hasData = SPI_processed >= 1; |
| 633 | if (!hasData) |
| 634 | { |
| 635 | break; |
| 636 | } |
| 637 | |
| 638 | if (SPI_tuptable) |
| 639 | { |
| 640 | for (int tupleNumber = 0; tupleNumber < (int) SPI_processed; tupleNumber++) |
| 641 | { |
| 642 | bool isNull = false; |
| 643 | |
| 644 | /* Attr 2 is collection_name */ |
| 645 | AttrNumber collectionNameAttr = 2; |
| 646 | Datum collectionNameDatum = SPI_getbinval(SPI_tuptable->vals[tupleNumber], |
| 647 | SPI_tuptable->tupdesc, |
| 648 | collectionNameAttr, |
| 649 | &isNull); |
| 650 | |
| 651 | if (isNull) |
| 652 | { |
| 653 | continue; |
| 654 | } |
| 655 | |
| 656 | if (strcmp(TextDatumGetCString(collectionNameDatum), |
| 657 | "system.dbSentinel") == 0) |
| 658 | { |
| 659 | /* Skip the sentinel*/ |
| 660 | continue; |
| 661 | } |
| 662 | |
| 663 | /* Attr 3 is collection_id */ |
no test coverage detected