LCOV - code coverage report
Current view: top level - gdk - gdk_cross.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 51 55 92.7 %
Date: 2021-10-13 02:24:04 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #include "monetdb_config.h"
      10             : #include "gdk.h"
      11             : #include "gdk_private.h"
      12             : #include "gdk_system.h"
      13             : 
      14             : /* Calculate a cross product between bats l and r with optional
      15             :  * candidate lists sl for l and sr for r.
      16             :  * The result is two bats r1 and r2 which contain the OID (head
      17             :  * values) of the input bats l and r.
      18             :  * If max_one is set, r can have at most one row. */
      19             : gdk_return
      20       13481 : BATsubcross(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, bool max_one)
      21             : {
      22             :         BAT *bn1, *bn2 = NULL;
      23             :         struct canditer ci1, ci2;
      24             :         BUN cnt1, cnt2;
      25             :         oid *restrict p;
      26             :         BUN i, j;
      27             : 
      28       13481 :         cnt1 = canditer_init(&ci1, l, sl);
      29       13481 :         cnt2 = canditer_init(&ci2, r, sr);
      30             :         lng timeoffset = 0;
      31       13481 :         QryCtx *qry_ctx = MT_thread_get_qry_ctx();
      32       13481 :         if (qry_ctx != NULL) {
      33       13481 :                 timeoffset = (qry_ctx->starttime && qry_ctx->querytimeout) ? (qry_ctx->starttime + qry_ctx->querytimeout) : 0;
      34             :         }
      35             : 
      36       13481 :         if (max_one && cnt1 > 0 && cnt2 > 1) {
      37          51 :                 GDKerror("more than one match");
      38          51 :                 return GDK_FAIL;
      39             :         }
      40             : 
      41       13430 :         bn1 = COLnew(0, TYPE_oid, cnt1 * cnt2, TRANSIENT);
      42       13430 :         if (r2p)
      43       12762 :                 bn2 = COLnew(0, TYPE_oid, cnt1 * cnt2, TRANSIENT);
      44       13430 :         if (!bn1 || (r2p && !bn2)) {
      45           0 :                 BBPreclaim(bn1);
      46           0 :                 if (bn2)
      47           0 :                         BBPreclaim(bn2);
      48           0 :                 return GDK_FAIL;
      49             :         }
      50       13430 :         if (cnt1 > 0 && cnt2 > 0) {
      51       10732 :                 BATsetcount(bn1, cnt1 * cnt2);
      52       10732 :                 bn1->tsorted = true;
      53       10732 :                 bn1->trevsorted = cnt1 <= 1;
      54       10732 :                 bn1->tkey = cnt2 <= 1;
      55       10732 :                 bn1->tnil = false;
      56       10732 :                 bn1->tnonil = true;
      57       10732 :                 p = (oid *) Tloc(bn1, 0);
      58    10371702 :                 for (i = 0; i < cnt1; i++) {
      59    10360970 :                         GDK_CHECK_TIMEOUT_BODY(timeoffset, GOTO_LABEL_TIMEOUT_HANDLER(bailout));
      60    10360970 :                         oid x = canditer_next(&ci1);
      61   124148633 :                         for (j = 0; j < cnt2; j++) {
      62   113787663 :                                 *p++ = x;
      63             :                         }
      64             :                 }
      65       10732 :                 BATtseqbase(bn1, cnt2 == 1 ? *(oid *) Tloc(bn1, 0) : oid_nil);
      66             : 
      67       10732 :                 if (bn2) {
      68       10425 :                         BATsetcount(bn2, cnt1 * cnt2);
      69       10425 :                         bn2->tsorted = cnt1 <= 1 || cnt2 <= 1;
      70       10425 :                         bn2->trevsorted = cnt2 <= 1;
      71       10425 :                         bn2->tkey = cnt1 <= 1;
      72       10425 :                         bn2->tnil = false;
      73       10425 :                         bn2->tnonil = true;
      74       10425 :                         p = (oid *) Tloc(bn2, 0);
      75     8029274 :                         for (i = 0; i < cnt1; i++) {
      76     8018850 :                                 GDK_CHECK_TIMEOUT_BODY(timeoffset, GOTO_LABEL_TIMEOUT_HANDLER(bailout));
      77    29005358 :                                 for (j = 0; j < cnt2; j++) {
      78    20986625 :                                         *p++ = canditer_next(&ci2);
      79             :                                 }
      80     8018733 :                                 canditer_reset(&ci2);
      81             :                         }
      82       10424 :                         BATtseqbase(bn2, cnt1 == 1 ? *(oid *) Tloc(bn2, 0) : oid_nil);
      83             :                 }
      84             :         }
      85       13429 :         *r1p = bn1;
      86       13429 :         if (r2p)
      87       12761 :                 *r2p = bn2;
      88       13429 :         if (r2p)
      89       12761 :                 TRC_DEBUG(ALGO, "BATsubcross()=(" ALGOBATFMT "," ALGOBATFMT ")\n", ALGOBATPAR(bn1), ALGOBATPAR(bn2));
      90             :         else
      91         668 :                 TRC_DEBUG(ALGO, "BATsubcross()=(" ALGOBATFMT ")\n", ALGOBATPAR(bn1));
      92             :         return GDK_SUCCEED;
      93             : 
      94           1 :   bailout:
      95           1 :         BBPreclaim(bn1);
      96           1 :         BBPreclaim(bn2);
      97           1 :         return GDK_FAIL;
      98             : }

Generated by: LCOV version 1.14