473,626 Members | 3,325 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multicolumn Primary Key

We've got a table that has a definition as follows:

CREATE TABLE linking_table (
fk int8 REFERENCES source_table( pk1 ),
value int8,
PRIMARY KEY( fk1, value )
);

I would've thought that the multicolumn primary key would behave as a
multicolumn index is supposed to behave per

http://www.postgresql.org/docs/7.4/s...lticolumn.html

where the behavior of the index cascades from the left rightward across
any columns specified in WHERE.

But a query like

SELECT COUNT( * ) FROM linking_table WHERE fk = '42';

yields a sequential scan.

If I add an index to fk, then the same query yields an index scan, as I
would expect. Is this because, according to the docs, a primary key "is
merely a combination of UNIQUE and NOT NULL"?

If so, then why do primary keys afford index scans of single columns
specified as primary keys?

This is in postgres 7.4.5, btw.

-tfo
Nov 23 '05 #1
5 3060
How many rows in the table? If it's a small table PostgreSQL won't
consider using the index.

Otherwise, have you VACUUM ANALYZEd recently?

On Tue, Aug 31, 2004 at 12:00:11PM -0500, Thomas F. O'Connell wrote:
We've got a table that has a definition as follows:

CREATE TABLE linking_table (
fk int8 REFERENCES source_table( pk1 ),
value int8,
PRIMARY KEY( fk1, value )
);

I would've thought that the multicolumn primary key would behave as a
multicolumn index is supposed to behave per

http://www.postgresql.org/docs/7.4/s...lticolumn.html

where the behavior of the index cascades from the left rightward across
any columns specified in WHERE.

But a query like

SELECT COUNT( * ) FROM linking_table WHERE fk = '42';

yields a sequential scan.

If I add an index to fk, then the same query yields an index scan, as I
would expect. Is this because, according to the docs, a primary key "is
merely a combination of UNIQUE and NOT NULL"?

If so, then why do primary keys afford index scans of single columns
specified as primary keys?

This is in postgres 7.4.5, btw.

-tfo
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBNO7JY5T wig3Ge+YRAmuTAK CX/0p5KC5SY+psqlEj a62dARIbGgCgu/Zl
nXz94GwoRnPxoM2 XV5LRL3o=
=tMg/
-----END PGP SIGNATURE-----

Nov 23 '05 #2

On Aug 31, 2004, at 4:34 PM, Martijn van Oosterhout wrote:
How many rows in the table? If it's a small table PostgreSQL won't
consider using the index.
300,000+
Otherwise, have you VACUUM ANALYZEd recently?


Argh! That seems to have been it. I have pg_autovacuum running, so it
didn't occur to me.

Thanks.

-tfo
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #3
Thomas F.O'Connell wrote:
On Aug 31, 2004, at 4:34 PM, Martijn van Oosterhout wrote:
Otherwise, have you VACUUM ANALYZEd recently?


Argh! That seems to have been it. I have pg_autovacuum running, so it
didn't occur to me.


pg_autovacuum only knows about table activity that has taken place while
it's running. Example: Table A has an analyze threshold of 1000, if
you perform 999 updates on table A, then kill and restart pg_autovacuum,
you will have to perform another 1000 updates before pg_autovacuum
performs an ANALYZE. This is a large limitation of the current
implementation.

I tried to fix this for 8.0, but my autovacuum improvements didn't make
the cut.

Matthew
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #4
On Tuesday 31 August 2004 3:49 pm, Matthew T. O'Connor wrote:
Thomas F.O'Connell wrote:
On Aug 31, 2004, at 4:34 PM, Martijn van Oosterhout wrote:
Otherwise, have you VACUUM ANALYZEd recently?


Argh! That seems to have been it. I have pg_autovacuum running,
so it didn't occur to me.


pg_autovacuum only knows about table activity that has taken place
while it's running. Example: Table A has an analyze threshold of
1000, if you perform 999 updates on table A, then kill and restart
pg_autovacuum, you will have to perform another 1000 updates before
pg_autovacuum performs an ANALYZE. This is a large limitation of
the current implementation.

I tried to fix this for 8.0, but my autovacuum improvements didn't
make the cut.


As a quick-'n'-dirty "fix", what about a command-line option to
autovacuum that tells it to vacuum analyze all tables on startup? At
least it would start in a somewhat known condition.

Cheers,
Steve

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #5
Steve Crawford wrote:
On Tuesday 31 August 2004 3:49 pm, Matthew T. O'Connor wrote:
pg_autovacu um only knows about table activity that has taken place
while it's running. Example: Table A has an analyze threshold of
1000, if you perform 999 updates on table A, then kill and restart
pg_autovacuum , you will have to perform another 1000 updates before
pg_autovacu um performs an ANALYZE. This is a large limitation of
the current implementation.

I tried to fix this for 8.0, but my autovacuum improvements didn't
make the cut.


As a quick-'n'-dirty "fix", what about a command-line option to
autovacuum that tells it to vacuum analyze all tables on startup? At
least it would start in a somewhat known condition.


I thought having pg_autovacuum do that, but seemed like overkill, but
perhaps a command line option wouldn't be a bad thing. However, you
could also just as easily do a manual vacuum analyze whenever you like.

Matthew

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #6

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

Similar topics

4
2617
by: kackson | last post by:
Hi. I attempted to create a multicolumn listbox for my web based aspx application. I search the net, all I get is something like listview or I need to have system.windwos.form. But for the goodness of my brain, I cant seem to find it anywhere and just not able to do a "using System.WIndows.form". WHere on earth can I get this work? Please help! I just need a simple multicolumn listbox. Why is this so difficult? :(
1
5048
by: zoneal | last post by:
Hi I have a form with a listbox, two comboboxes and two Radiobuttons. What I want to do is make a selection from both comboboxes and either Radiobutton and display these three elements across the top of the listbox eg. 5, 10, 'Go' As I need multiple rows of data I have a button to 'Load' this to the listbox. I'm stuck though as I'm having difficulty loading this correctly. Question: Woulkd I be better off with a datagrid for this job,...
1
2032
by: Thomas Yagel | last post by:
I have a situtation where a particular table includes a timestamp column and a id column. The query I am working with right now filters based on timestamp and orders based on ID. I have not found enough information about how multicolumn indexes actually work to determine if one will help me in this case, but I think that it might. Right now the index that I have on timestamp is not used because the Primary Key(ID) index is chosen for...
7
6113
by: Paul Bromley | last post by:
How can I use this please - I need 2 columns. I have been having difficulty finding info on this and the 2005 Treeview control today. Many thanks for any links or info, Paul Bromley
2
2034
by: dev.amit | last post by:
Hello Friends I am a new bee to the world of vb. I have an appication in the MS Access and now i have to convert it to the Vb. I am having problem creating multicolumn Listbox in the vb form. I have dont it quite simply with ease in Access but here i am blank. 1.I want to show Three column in the list box. 2. I would populate this with the help of a query which picks data from two tables
4
3178
by: sql_server_user | last post by:
Hi, I have a history table with about 400 million rows, with a unique composite nonclustered index on two columns (object id and time period) which is used for most of the queries into the table, and an identity column for the clustered primary key. Many of my queries use correlated subqueries to pull unique history rows from the history table for each of a set of objects from the object table, for instance, pulling the earliest...
10
4033
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever) then How would you accomplish this using a ListView ?
5
17743
by: WRH | last post by:
Hello I want to have a multicolumn listbox. I never used one before so I looked at a Help example. I set the multicolumn property and the column width and tested with this example... this.listBox3.Items.AddRange(new object { "Item 1, column 1", "Item 2, column 1", "Item 3, column 1",
3
5638
balabaster
by: balabaster | last post by:
Hey guys and gals, I'm not sure if this is the simplest way to do this or if someone can throw any other ideas out there. I'm looking to build a treeview inside a listbox...or have a multicolumn treeview. Having done some research it seems there was some rather extensive and laborious methods for achieving such an effect in VB6 but none of them satisfactory and the only method I can find that looks anywhere near like it might possibly be...
0
8266
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
8199
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
8705
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...
1
8365
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6125
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
4092
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...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.