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

  • Home
  • SEARCH
  • 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 8056327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:40:13+00:00 2026-06-05T08:40:13+00:00

I have two tables: trips: id_trip, id_object, trip_date, delta (8980026 rows) ranges: id_range, id_object,

  • 0

I have two tables:

  • trips: id_trip, id_object, trip_date, delta (8980026 rows)
  • ranges: id_range, id_object, date_since, date_until (18490 rows)

I need to optimize the following select statement

  select r.id_range, sum(t.delta) sum_deltas
    from trips t,
         ranges r
   where t.id_object = r.id_object
     and t.trip_date between r.date_since and r.date_until
group by r.id_range

according to the condition there is always exactly one matching row for trip in ‘ranges’

  • the trips table is constantly growing, but there are no updates or deletions
  • table ranges may change from time to time in any way (deletions, updates, inserts), so function based index is not the way 🙁
  • there are indexes on id_object (in both tables) and date_since (in trips)

Does anyone have an idea how to speed things up, is it even possible?

  • 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-05T08:40:14+00:00Added an answer on June 5, 2026 at 8:40 am

    It’s always possible to speed things up; it just may not be worth the time / effort / money / disk-space / additional overheads etc.

    Firstly please use the explicit join syntax. It’s been the SQL standard for a few decades now and it helps avoid a lot of potential errors. Your query would become:

    select r.id_range, sum(t.delta) sum_deltas
      from trips t
      join ranges r
        on t.id_object = r.id_object
       and t.trip_date between r.date_since and r.date_until
     group by r.id_range
    

    This query would imply that you need two indexes – unique if possible. On ranges you should have an index on id_object, date_since, date_until. The index on trips would be id_object, trip_date. If trips were smaller I might consider adding delta on to the end of that index so you never enter the table at all but only do a index scan. As it stands you’re going to have to do a table access by index rowid.

    Having written all that your problem may be slightly different. You’re going to be full-scanning both tables with this query. Your problem might be the indexes. If the optimizer is using the indexes then it’s possible you’re doing an index unique/range scan for each id_object in trips or ranges and then, because of the use of columns not in the indexes you will be doing an table access by index rowid. This can be massively expensive.

    Try adding a hint to force a full-scan of both tables:

    select /*+ full(t) full(r) */ r.id_range, sum(t.delta) sum_deltas
      from trips t
      join ranges r
        on t.id_object = r.id_object
       and t.trip_date between r.date_since and r.date_until
     group by r.id_range
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have two tables; Drivers keyed by DriverId and Trips with foreign keys
I have two auditing tables: Trip_aud and Event_aud. They were created in Envers, but
i have two tables products and reviews each product has several reviews linked by
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I have two tables on a webform. On a button click I want to
i have two tables both are related with primary-foreign key ralation and i have
I have two tables, the first has a primary key that is an identity,
I have two tables: Videos -------------- VideoID VideoGroupID CreatorUserID and VideoTags -------------- VideoID TagID
I have two tables, one for routes and one for airports. Routes contains just
Suppose I have two tables: Group ( id integer primary key, someData1 text, someData2

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.