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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:11:01+00:00 2026-05-15T20:11:01+00:00

Query below takes 20 seconds to run. user_table has 40054 records. other_table has 14000

  • 0

Query below takes 20 seconds to run. user_table has 40054 records. other_table has 14000 records

select count(a.user_id) from user_table a, other_table b 
where a.user_id = b.user_id;

our restriction is that any query running more than 8 seconds gets killed…>_< I’ve ran explain plans, asked questions here but based on our restrictions I can not get this query to run in less than 8 secs. So I made a loop out of it.

begin
FOR i IN role_user_rec.FIRST .. role_user_rec.LAST LOOP
            SELECT COUNT (a.user_id) INTO v_into FROM user_table a
            WHERE TRIM(role_user_rec(i).user_id) = TRIM(a.user_id);
          v_count := v_count + v_into;
END LOOP;

I know restrictions suck and this is not effecient way to do things but is there any other way to make this loop run faster?

  • 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-05-15T20:11:02+00:00Added an answer on May 15, 2026 at 8:11 pm

    Can you get around the loop? I agree with Janek, if the query itself takes too long you may have to do a different method to get it. And to agree with Mark, if you can do it in one query then by all means do so. But if you cannot, drop the loop as below

    But try it something like this; drop the loop:

    /*
    --set up for demo/test
    Create Type Testusertype As Object(User_Id Number , User_Name Varchar2(500));
    CREATE TYPE TESTUSERTYPETABLE IS TABLE OF TESTUSERTYPE;
    */
    
    Declare
      Tutt Testusertypetable;
      TOTALCOUNT NUMBER ;
    Begin 
    
        Select Testusertype(Object_Id,Object_Name)
           bulk collect into TUTT
          From User_Objects
        ;
    
    Dbms_Output.Put_Line(Tutt.Count);
    
    Select Count(*) Into Totalcount 
      From User_Objects Uu 
           Inner Join Table(Tutt) T
           ON T.User_Id = Uu.Object_Id;
    
    Dbms_Output.Put_Line(Tutt.Count);
    Dbms_Output.Put_Line(Totalcount);
    
    End ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the query below. Using a LEFT OUTER join takes 9 seconds to
I have an SQL query (below) that essentially takes a student from tbStudents, and
I have the query below that when run it says that 325 rows were
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
hey guys, i have a query in sql server which takes atleast 10-15 seconds
I have a query like this select Count(1) as Count, pt.Name as TypeName, pt.ID
I have an SQL query similar to below: SELECT NAME, MY_FUNCTION(NAME) -- carries out
SCENARIO I need to select records from test_userData based on a 1-to-1 match from
My native query below is working fine oracle sqlplus. But through JPA native query,
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?

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.