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-12-19 20:05:57 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       82385 : statistics_atom_max(mvc *sql, atom *v1, atom *v2)
      34             : {
      35       82385 :         sql_subtype super;
      36       82385 :         atom *cast1 = v1, *cast2 = v2;
      37             : 
      38       82385 :         supertype(&super, &v1->tpe, &v2->tpe);
      39       82385 :         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       82384 :         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       82384 :         return atom_cmp(cast1, cast2) > 0 ? cast1 : cast2;
      50             : }
      51             : 
      52             : static inline atom *
      53       80669 : statistics_atom_min(mvc *sql, atom *v1, atom *v2)
      54             : {
      55       80669 :         sql_subtype super;
      56       80669 :         atom *cast1 = v1, *cast2 = v2;
      57             : 
      58       80669 :         supertype(&super, &v1->tpe, &v2->tpe);
      59       80669 :         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       80668 :         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       80668 :         return atom_cmp(cast1, cast2) > 0 ? cast2 : cast1;
      70             : }
      71             : 
      72             : static inline void
      73     3644403 : set_minmax_property(mvc *sql, sql_exp *e, rel_prop kind, atom *val)
      74             : {
      75     3644403 :         if (val == NULL)
      76             :                 return;
      77             : 
      78     3644401 :         sql_subtype *tpe = exp_subtype(e);
      79     3644401 :         prop *found = find_prop(e->p, kind);
      80             : 
      81     3644399 :         if (subtype_cmp(&val->tpe, tpe) != 0) { /* make sure it's the same type */
      82        4726 :                 val = atom_copy(sql->sa, val);
      83        4726 :                 if (!(val = atom_cast(sql->sa, val, tpe)))
      84             :                         return;
      85             :         }
      86     3644341 :         if (found) {
      87     2081906 :                 found->value.pval = val;
      88             :         } else {
      89     1562435 :                 prop *p = e->p = prop_create(sql->sa, kind, e->p);
      90     1562435 :                 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