Unix Technical Forum

why provide cross type arithmetic operators

This is a discussion on why provide cross type arithmetic operators within the pgsql Bugs forums, part of the PostgreSQL category; --> there are many cross type arithmetic operators, like int2 + int4, int8 + int4, I think these can be ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 11:14 AM
ykhuang
 
Posts: n/a
Default why provide cross type arithmetic operators

there are many cross type arithmetic operators, like int2 + int4, int8 +
int4, I think these can be deleted. Here are the reasons, after deleted,
int2 + int4 will choose the operator int4 + int4, int8 + int4 choose int8 +
int8, Is that ok? Thanks.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 11:14 AM
ykhuang
 
Posts: n/a
Default Re: why provide cross type arithmetic operators

for example,

postgres=# select int2'1' + int8'1';
ERROR: operator is not unique: smallint + bigint
LINE 1: select int2'1' + int8'1';
^
HINT: Could not choose a best candidate operator. You may need to add
explicit
type casts.

there are int4 + int8 and int8 + int8, but no int2 + int8, so two operators
available, they are int4 + int8 and int8 + int8,
system can't choose a best candidate operator.


"ykhuang" <hyk@ruc.edu.cn> 写入消息新闻:fn3n3o$1g5r$1@news.hub.org...
> there are many cross type arithmetic operators, like int2 + int4, int8 +
> int4, I think these can be deleted. Here are the reasons, after deleted,
> int2 + int4 will choose the operator int4 + int4, int8 + int4 choose int8
> + int8, Is that ok? Thanks.
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 11:14 AM
Gregory Stark
 
Posts: n/a
Default Re: why provide cross type arithmetic operators

"ykhuang" <hyk@ruc.edu.cn> writes:

> there are many cross type arithmetic operators, like int2 + int4, int8 +
> int4, I think these can be deleted. Here are the reasons, after deleted,
> int2 + int4 will choose the operator int4 + int4, int8 + int4 choose int8 +
> int8, Is that ok? Thanks.


Then the system wouldn't be able to use indexes as flexibly. For example if
you have an index on an int2 column and perform a query with a restriction
like "int2col = 1" the system wouldn't find a matching =(int2,int4) operator
and would instead have to do a sequential scan casting the int2 column to an
int4 when checking each row.


--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 11:14 AM
Tom Lane
 
Posts: n/a
Default Re: why provide cross type arithmetic operators

Gregory Stark <stark@enterprisedb.com> writes:
> "ykhuang" <hyk@ruc.edu.cn> writes:
>> there are many cross type arithmetic operators, like int2 + int4, int8 +
>> int4, I think these can be deleted. Here are the reasons, after deleted,
>> int2 + int4 will choose the operator int4 + int4, int8 + int4 choose int8 +
>> int8, Is that ok? Thanks.


> Then the system wouldn't be able to use indexes as flexibly. For example if
> you have an index on an int2 column and perform a query with a restriction
> like "int2col = 1" the system wouldn't find a matching =(int2,int4) operator
> and would instead have to do a sequential scan casting the int2 column to an
> int4 when checking each row.


This is a reason not to remove "redundant" indexable operators, but the
argument doesn't have a lot of force for non-indexable ones.

I looked into this, and the reason we fail to resolve int2 + int8 is
that after the "prefer more exact matches" test (the first heuristic in
func_select_candidate) we are down to int8 + int8 and int4 + int8,
and none of the remaining heuristics can prefer one over the other.
On the other hand, we resolve int2 < int8 just fine because there's an
exact match.

So it seems that the problem with cross-type operators is not so much
having them as having incomplete sets of them. We could fix this case
either by adding int2 + int8 or by removing int4 + int8, and simplicity
would seem to argue for the latter.

A different approach would be to add a heuristic preferring
same-input-type operators over others. (We currently apply that idea
only when one of the inputs is "unknown" type, which is why
'1' + int8'1' works.) It's a bit scary to wonder what cases that might
break, though.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 11:15 AM
Bruce Momjian
 
Posts: n/a
Default Re: why provide cross type arithmetic operators


Added to TODO:

* Add more cross-data-type operators

http://archives.postgresql.org/pgsql...1/msg00189.php


---------------------------------------------------------------------------

ykhuang wrote:
> there are many cross type arithmetic operators, like int2 + int4, int8 +
> int4, I think these can be deleted. Here are the reasons, after deleted,
> int2 + int4 will choose the operator int4 + int4, int8 + int4 choose int8 +
> int8, Is that ok? Thanks.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend


--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 11:15 AM
Tom Lane
 
Posts: n/a
Default Re: why provide cross type arithmetic operators

Bruce Momjian <bruce@momjian.us> writes:
> Added to TODO:
> * Add more cross-data-type operators
> http://archives.postgresql.org/pgsql...1/msg00189.php


Uh ... that is exactly 180 degrees away from the point of the thread.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-10-2008, 11:15 AM
Bruce Momjian
 
Posts: n/a
Default Re: why provide cross type arithmetic operators

Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > Added to TODO:
> > * Add more cross-data-type operators
> > http://archives.postgresql.org/pgsql...1/msg00189.php

>
> Uh ... that is exactly 180 degrees away from the point of the thread.


OK, I see now, updated:

* Simplify integer cross-data-type operators


Email text is:

http://archives.postgresql.org/pgsql...1/msg00199.php

So it seems that the problem with cross-type operators is not so much
having them as having incomplete sets of them. We could fix this case
either by adding int2 + int8 or by removing int4 + int8, and simplicity
would seem to argue for the latter.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:17 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com