473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create 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,(acl).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.866 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.489 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.310 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'::text 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_parent ON rt_host(parent);
CREATE INDEX rt_host_idx_guid ON rt_host(guid);
CREATE INDEX rt_host_idx_active ON rt_host (guid) WHERE (deleted IS NULL) AND
(is_scan = false);

CREATE TABLE object (
guid integer NOT NULL DEFAULT nextval('guid_seq'),
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_cluster_id()] NOT NULL,
clu_rnode integer DEFAULT f_get_my_cluster_id() NOT NULL
) WITHOUT OIDS;
CREATE UNIQUE INDEX object_guid_idx ON object(guid);

CREATE OR REPLACE FUNCTION f_all_acl(INTEGER) RETURNS t_acl_rwl AS '
SELECT COALESCE(read,false),COALESCE(write,false),COALESC E(list,false) FROM
acl_cache WHERE aclobj=$1
AND userid=f_get_sess_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 1625
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,(acl).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,(acl).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
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...
5
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...
4
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...
10
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...
2
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
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...
10
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...
2
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...
13
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.