473,657 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird behavior with selects and composite data types

When using the (tbl).field notation for selecting a specific field from a
composite field then the query returning the field is executed once per
field. An example is giving below. The runtime is directly related to the
number of fields accessed.

The following tests is done with seqscan disabled - but I have confirmed the
exact same behavior with seqscan enabled.

Another side effect of this is the case where f_all_acl() actually modifies or
adds data, then it would actually be done once per column selected. This is
definately not what people expect (or the standard tells if there's any).

Any bright heads here. I confirmed the exact same behavior on both 7.4.5 and
8.0-beta-2. A workaround would also be gladly accepted.

---
Nicolai Petri

---------------- EXPLAINS ---------------------------------------------
dmon2=# explain analyse
SELECT guid, (acl).read, (acl).write,(ac l).list FROM (select guid,
f_all_acl(guid) as acl from rt_host) as i;
QUERY PLAN
-------------------------------------------------------------------------------------------------------
Seq Scan on rt_host (cost=100000000 .00..100000001. 37 rows=21 width=4)
(actual time=4.466..9.8 66 rows=
21 loops=1)
Total runtime: 10.017 ms
(2 rows)

dmon2=# explain analyse
dmon2-# SELECT guid, (acl).read, (acl).write FROM (select guid,
f_all_acl(guid) as acl from rt_host) as i;
QUERY PLAN
-------------------------------------------------------------------------------------------------------
Seq Scan on rt_host (cost=100000000 .00..100000001. 31 rows=21 width=4)
(actual time=2.833..6.4 89 rows=
21 loops=1)
Total runtime: 6.637 ms
(2 rows)
dmon2=#

dmon2=# explain analyse
dmon2-# SELECT guid, (acl).read FROM (select guid, f_all_acl(guid) as acl
from rt_host) as i;
QUERY PLAN
-------------------------------------------------------------------------------------------------------
------------
Seq Scan on rt_host (cost=100000000 .00..100000001. 26 rows=21 width=4)
(actual time=1.381..3.3 10 rows=
21 loops=1)
Total runtime: 3.444 ms
(2 rows)
----------- (table defs) -----------------
CREATE TABLE acl_cache (
aclobj int4 not null,
modified timestamptz not null default now()
) WITHOUT OIDS;

CREATE TABLE rt_host (
hostname text NOT NULL,
"domain" text NOT NULL,
parent INTEGER,
location INTEGER,
alias text DEFAULT 'hostname'::tex t NOT NULL,
os text,
is_scan boolean DEFAULT 'f' NOT NULL
) INHERITS (object) WITHOUT OIDS;
ALTER TABLE rt_host ALTER type SET DEFAULT 3;
CREATE INDEX rt_host_idx_par ent ON rt_host(parent) ;
CREATE INDEX rt_host_idx_gui d ON rt_host(guid);
CREATE INDEX rt_host_idx_act ive ON rt_host (guid) WHERE (deleted IS NULL) AND
(is_scan = false);

CREATE TABLE object (
guid integer NOT NULL DEFAULT nextval('guid_s eq'),
type integer NOT NULL DEFAULT 0,
-- l_version integer DEFAULT 1 NOT NULL,
created timestamptz DEFAULT now() NOT NULL,
modified timestamptz DEFAULT now() NOT NULL,
deleted timestamptz,
systemobj boolean DEFAULT false NOT NULL,
clu_map integer[] DEFAULT ARRAY[f_get_my_cluste r_id()] NOT NULL,
clu_rnode integer DEFAULT f_get_my_cluste r_id() NOT NULL
) WITHOUT OIDS;
CREATE UNIQUE INDEX object_guid_idx ON object(guid);

CREATE OR REPLACE FUNCTION f_all_acl(INTEG ER) RETURNS t_acl_rwl AS '
SELECT COALESCE(read,f alse),COALESCE( write,false),CO ALESCE(list,fal se) FROM
acl_cache WHERE aclobj=$1
AND userid=f_get_se ss_user() LIMIT 1;
' LANGUAGE SQL STABLE STRICT;
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #1
1 1649
li***@petri.cc writes:
When using the (tbl).field notation for selecting a specific field from a
composite field then the query returning the field is executed once per
field.
You mean that the function yielding the field is executed repeatedly:
SELECT guid, (acl).read, (acl).write,(ac l).list FROM (select guid,
f_all_acl(guid) as acl from rt_host) as i;


This will be flattened into

SELECT guid, (f_all_acl(guid )).read, (f_all_acl(guid )).write,
(f_all_acl(guid )).list
FROM rt_host;

which is generally a good thing, but perhaps not if f_all_acl() is
expensive to compute. The standard hack at present for preventing
such flattening without changing the query semantics is to insert
an OFFSET 0 clause into the subselect:

SELECT guid, (acl).read, (acl).write,(ac l).list FROM (select guid,
f_all_acl(guid) as acl from rt_host offset 0) as i;

Note that this has nothing to do with field selection in particular,
it's just a general property of the subselect-in-FROM implementation.

regards, tom lane

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

http://archives.postgresql.org

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2075
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed to get a working system just about finished. I am building an interface for our customer service folks to use to manage registered customers and am seeing some weird behavior.
5
2203
by: hasden | last post by:
I'm working in .NET and I can't seem to get the behavior that I need from the combobox. I'm sure it's possible, I just don't have the .NET experience. Any help would be greatly appreciated. I need a combobox with the following behavior: - The user can type in any text they want - When the user clicks the drop down button and selects an item from the combobox the text for that item should be appended to the end of the text already...
4
1304
by: Sahil Malik [MVP] | last post by:
Okay so lets say I have a valuetype - lets say DateTime. Look at this code . List<DateTime> dt = new List<DateTime>() ; dt.Add(new dateTime(1999,12,1)) dt.AddDays(1) ; <--- This statement won't actually change the date time stored in the List<T> dt.
10
4008
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
2
2646
by: pkpatil | last post by:
Hi, Can a private composite object in a class access private or protected members of base class? For e.g. class composite { void memberFunction(); };
14
5027
by: dave.dolan | last post by:
Basically I'd like to implement the composite design pattern with leaves that are either of reference or value types, but even using generics I can't seem to avoid boxing (using ArrayList or Object) Is this even possible, or is the composite pattern doomed to use the System.Object type forever? I have tried using interfaces with generics, but I always stumble on the Value property (when trying to return the value of a particular node)
10
2912
by: Ben | last post by:
Hi, i have a weird problem and i don't know who is responsible for this: IIS, excel or asp.net. My problem: we use an asp.net 2.0 application under IIS 6.0 (server 2003 sp2) which must write data from a form into a table in excel files (i know excel is not really recommended for that, but it's excel).There are a lot of excel files, all in the same directory with the same privileges (Network service has
2
1432
by: Jimmy V | last post by:
Hey guys and gals, I am creating a composite control and need to expose the ImageList and all related properties of a label in this control; I do not want to expose the entire label. What I am looking for is a way to get the ImageKey and ImageIndex properties to behave the same as they do with the base label control, i.e. I want to a drop down with the available values in the ImageKey and ImageIndex in the property window when a user...
13
2089
by: Dave Rado | last post by:
Hi The W3C css validation service at http://jigsaw.w3.org/css-validator/ claims that: {font-family: "Book Antiqua", Palatino, "Times New Roman", "Times Roman" serif} is invalid on the grounds that "Too many values or values are not recognized "
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.