LCOV - code coverage report
Current view: top level - sql/server - rel_statistics.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 33 100.0 %
Date: 2024-11-15 19:37:45 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #ifndef _REL_STATISTICS_H_
      14             : #define _REL_STATISTICS_H_
      15             : 
      16             : #include "sql_relation.h"
      17             : #include "sql_mvc.h"
      18             : #include "rel_exp.h"
      19             : 
      20             : typedef void (*lookup_function) (mvc*, sql_exp*);
      21             : 
      22             : struct function_properties {
      23             :         const char *name;
      24             :         lookup_function func;
      25             : };
      26             : 
      27             : #define atom_max(X,Y) atom_cmp(X, Y) > 0 ? X : Y
      28             : #define atom_min(X,Y) atom_cmp(X, Y) > 0 ? Y : X
      29             : 
      30             : extern void sql_column_get_statistics(mvc *sql, sql_column *c, sql_exp *e);
      31             : 
      32             : static inline atom *
      33       75959 : statistics_atom_max(mvc *sql, atom *v1, atom *v2)
      34             : {
      35       75959 :         sql_subtype super;
      36       75959 :         atom *cast1 = v1, *cast2 = v2;
      37             : 
      38       75959 :         supertype(&super, &v1->tpe, &v2->tpe);
      39       75959 :         if (subtype_cmp(&v1->tpe, &super) != 0) {
      40           2 :                 cast1 = atom_copy(sql->sa, v1);
      41           2 :                 if (!(cast1 = atom_cast(sql->sa, cast1, &super)))
      42             :                         return NULL;
      43             :         }
      44       75958 :         if (subtype_cmp(&v2->tpe, &super) != 0) {
      45           4 :                 cast2 = atom_copy(sql->sa, v2);
      46           4 :                 if (!(cast2 = atom_cast(sql->sa, cast2, &super)))
      47             :                         return NULL;
      48             :         }
      49       75958 :         return atom_cmp(cast1, cast2) > 0 ? cast1 : cast2;
      50             : }
      51             : 
      52             : static inline atom *
      53       74674 : statistics_atom_min(mvc *sql, atom *v1, atom *v2)
      54             : {
      55       74674 :         sql_subtype super;
      56       74674 :         atom *cast1 = v1, *cast2 = v2;
      57             : 
      58       74674 :         supertype(&super, &v1->tpe, &v2->tpe);
      59       74674 :         if (subtype_cmp(&v1->tpe, &super) != 0) {
      60           2 :                 cast1 = atom_copy(sql->sa, v1);
      61           2 :                 if (!(cast1 = atom_cast(sql->sa, cast1, &super)))
      62             :                         return NULL;
      63             :         }
      64       74673 :         if (subtype_cmp(&v2->tpe, &super) != 0) {
      65         200 :                 cast2 = atom_copy(sql->sa, v2);
      66         200 :                 if (!(cast2 = atom_cast(sql->sa, cast2, &super)))
      67             :                         return NULL;
      68             :         }
      69       74673 :         return atom_cmp(cast1, cast2) > 0 ? cast2 : cast1;
      70             : }
      71             : 
      72             : static inline void
      73     3384574 : set_minmax_property(mvc *sql, sql_exp *e, rel_prop kind, atom *val)
      74             : {
      75     3384574 :         if (val == NULL)
      76             :                 return;
      77             : 
      78     3384572 :         sql_subtype *tpe = exp_subtype(e);
      79     3384579 :         prop *found = find_prop(e->p, kind);
      80             : 
      81     3384581 :         if (subtype_cmp(&val->tpe, tpe) != 0) { /* make sure it's the same type */
      82        3972 :                 val = atom_copy(sql->sa, val);
      83        3972 :                 if (!(val = atom_cast(sql->sa, val, tpe)))
      84             :                         return;
      85             :         }
      86     3384507 :         if (found) {
      87     1928142 :                 found->value.pval = val;
      88             :         } else {
      89     1456365 :                 prop *p = e->p = prop_create(sql->sa, kind, e->p);
      90     1456365 :                 p->value.pval = val;
      91             :         }
      92             : }
      93             : 
      94             : extern sql_hash *sql_functions_lookup __attribute__((__visibility__("hidden")));
      95             : extern void initialize_sql_functions_lookup(allocator *sa) __attribute__((__visibility__("hidden")));
      96             : 
      97             : #endif /*_REL_STATISTICS_H_*/

Generated by: LCOV version 1.14