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 8883605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:51:15+00:00 2026-06-14T20:51:15+00:00

I have a table of edge like this: ——————————- | id | arg1 |

  • 0

I have a table of edge like this:

-------------------------------
| id | arg1 | relation | arg2 |
-------------------------------
| 1  |   1  |     3    |   4  |
-------------------------------
| 2  |   2  |     6    |   5  |
-------------------------------

where arg1, relation and arg2 reference to the ids of objects in another object table:

--------------------
| id | object_name |
--------------------
| 1  |   book      |
--------------------
| 2  |   pen       |
--------------------
| 3  |   on        |
--------------------
| 4  |   table     |
--------------------
| 5  |   bag       |
--------------------
| 6  |   in        |
--------------------

What I want to do is that, considering performance issues (a very big table more than 50 million of entries) display the object_name for each edge entry rather than id such as:

---------------------------
| arg1 | relation | arg2  |
---------------------------
| book |    on    | table |
---------------------------
|  pen |    in    | bag   |
---------------------------

What is the best select query to do this? Also, I am open to suggestions for optimizing the query – adding more index on the tables etc…

EDIT: Based on the comments below:

1) @Craig Ringer: PostgreSQL version: 8.4.13 and only index is id for both tables.

2) @andrefsp: edge is almost x2 times bigger than object.

  • 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-14T20:51:16+00:00Added an answer on June 14, 2026 at 8:51 pm

    It won’t get cheaper than this:

    SELECT o1.object_name, r1.object_name, o2.object_name
    FROM   edge e
    JOIN   object o1 ON o1.id = e.arg1
    JOIN   object  r ON  r.id = e.relation
    JOIN   object o2 ON o2.id = e.arg2;
    

    And you don’t need more indexes. The one on object.id is the only one needed for this query.

    But I seriously doubt that you want to retrieve 50 millions of rows at once, and in no particular order. You still didn’t give the full picture.

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

Sidebar

Related Questions

I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table
I have table with two columns (varchar from, varchar to). This table represents connections
This png-24 image looks like its color extends completely to the edge of its
I have a SQL table that maps, say, authors and books. I would like
I am using jqGrid, and have it set up like this: <body> <div> Header
I have a standard grouped table view. I would like to add a shadow
I have a selectable table (jQuery UI selectable). How do i access the edge
I've got a table that looks like this: CREATE TABLE CustomerXmlData (CustomerId int, CustomerData
I have table with around 70 000 rows. There is 6000 rows that i

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.