Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8444079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:18:44+00:00 2026-06-10T09:18:44+00:00

This table containg user’s photos (thumbnails and full). Most of queries will have a

  • 0

This table containg user’s photos (thumbnails and full).
Most of queries will have a “WHERE user_id = ?” condition.

CREATE TABLE photos (
  "photo_id" serial, -- serial is postgres' autoincrement
  "user_id" integer not null, -- foreign key to users table
  "filename_thumbnail_50" varchar not null,
  "filename_thumbnail_75" varchar not null, -- 75px x 75px thumbnail
  "filename_full" varchar not null,
  PRIMARY KEY ("photo_id", "user_id")
);

What’s the best design and/or performance design for this usecase:
– Two columns primary key like the above example ?
– One primary key (photo_id) and an index on user_id ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:18:46+00:00Added an answer on June 10, 2026 at 9:18 am

    The primary key should follow your business rules and nothing else. As a photo as such does not have a “real” (i.e. natural) primary key, using a serial as the PK absolutely makes sense.

    Extending the primary key with user_id does not make any sense and does not serve any purpose (as the photo_id will be unique anyway, you only add overhead to the index maintainence). And with the user_id being the second column in the index it is very unlikely it will be used for a query that limits on user_id (not impossible but unlikely)

    So I would go stick with the PK on photo_id and add an index on user_id (it’s always a good idea to index foreign key columns anyway).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains some user data: user_id | guest_id | time_seen
Given that I have a table contains user data, like this: userID calltime result
I have two tables. Table user contains user_id, user_name. Table Transactions contains user_id, transactions
I have a mysql database table that contains multiple user photos. I am trying
I have this table that contains the ad id and the user id. Any
I have table and this table contain result column with some entries. I just
I have a table and this table contain multiple columns. I want to know
I have a table on my database called 'Log'. This Log table contains ID,
Greetings, fellow coders! I have this table that contains categories and subcategories (actually I
I have this table Test as Id, SomeValue, SomeText contains about a mill records,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.