Hi both,

I agree that the logical view should be one of a column with many duplications of the constant.

However, MonetDB used to never create this column physically, but instead create a view.
(Not sure how it works today!)

I suppose that Roberto wonders about the physical level query plan, i.e., why generate a column with the value replicated N times, instead of handling over to the UDF a view representing the same solution.

Greetings,

Arjen

On Mon, 4 Nov 2019 at 13:13, Panagiotis Koutsourakis <panagiotis.koutsourakis@monetdbsolutions.com> wrote:
Hi Roberto,

I would argue that replicating the constant is the correct behavior. With

SELECT a, 10 FROM mytable

you are actually requesting two columns, it just so happens that the second column has a constant value. In general a SQL SELECT statement returns a SQL relation. It *has* to replicate the constant, otherwise the result would not make sense.

Would it work if you called your UDF like as follows?

SELECT * FROM myfunc((SELECT a FROM mytable), 10);

Best regards,
Panos.

On 11/4/19 12:08 PM, Roberto Cornacchia wrote:
> Hi,
>
> When defining a UDF, e.g.
>   CREATE FUNCTION myfunc(a int, b int) RETURNS int
> we can have:
>
> - a scalar implementation
>   command myfunc(a:int, b:int) :int
>
> - a bulk implementation
>   command myfunc(a:bat[:int], b:bat[:int]) :bat[:int]
>
> - a mixed implementation (e.g. a is a column, b is scalar):
>   command myfunc(a:bat[:int], b:int) :bat[:int]
>
> I'm trying to understand what the restrictions are, if any, for the third
> case.
> Is it expected to be allowed in (a combination of) the following cases?
>
> - Interleaved bulk/scalar arguments
>   command myfunc(a:bat[:int], b:int, c:bat[:int]) :bat[:int]
>
> - Table-returning function
>   command myfunc(a:bat[:int], b:int) (:bat[:int], :bat[:int])
>
> - Table-returning function, used with a sub-select in input
>   SELECT * FROM myfunc( (SELECT a, 10 FROM mytable) );
>
> In particular I can't get the last one to work. Even though the sub-select
> has a constant as the second column, this constant seems to be first
> replicated into a full column and then given to myfunc() as a column.
>
> When the constant parameters are a few, that becomes a waste of time/space.
> Plus the annoyance of selecting the first value of a constant column for
> the actual internal implementation, which of course expects a scalar for
> those arguments.
>
> Am I missing something? Is there a way to make that work as I would expect?
>
> Thanks, Roberto
>
>
> _______________________________________________
> users-list mailing list
> users-list@monetdb.org
> https://www.monetdb.org/mailman/listinfo/users-list
>

_______________________________________________
users-list mailing list
users-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/users-list


--
====================================================================
ICIS, office M1.02.07                             Radboud University
Mercator 1                                        Faculty of Science
Toernooiveld 212                                      arjen@cs.ru.nl
NL-6525 EC Nijmegen, The Netherlands              +31-(0)24-365 2354
===================== http://www.informagus.nl/ ====================