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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:05:34+00:00 2026-06-14T14:05:34+00:00

I have a SQL-Statement which uses a Check-Function which takes a quite long time

  • 0

I have a SQL-Statement which uses a Check-Function which takes a quite long time for execution.

Now I want to Parallize the execution of the Check-Function, but it does not work.

Where is the mistake I made?

The sample below takes 5 Seconds to execute, but for my understanding it should take about 1 Second because of the parallelism.

Code Snippet for Testing:

CREATE TABLE PERSON AS
SELECT LEVEL AS ID, 'Person_'||LEVEL AS NAME
FROM DUAL 
CONNECT BY LEVEL <= 5;

CREATE OR REPLACE FUNCTION LONGCHECKFUNC(ID NUMBER)
RETURN NUMBER IS
BEGIN
    --Doing some very heavy Checks....
    DBMS_LOCK.SLEEP(1 /*second*/);
    RETURN 1;
END;

SELECT /*+PARALLEL(person, 5) */ *
 FROM PERSON
WHERE LONGCHECKFUNC(ID)=1;
  • 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-14T14:05:35+00:00Added an answer on June 14, 2026 at 2:05 pm
    CREATE TABLE PERSON
    PARTITION BY HASH(ID) PARTITIONS 16 /* <-- ADDED*/
    AS
    SELECT LEVEL AS ID, 'Person_'||LEVEL AS NAME
    FROM DUAL 
    CONNECT BY LEVEL <= 5;
    
    CREATE OR REPLACE FUNCTION LONGCHECKFUNC(ID NUMBER)
    RETURN NUMBER PARALLEL_ENABLE /* <-- ADDED*/ IS
    BEGIN
        --Doing some very heavy Checks....
        DBMS_LOCK.SLEEP(1 /*second*/);
        RETURN 1;
    END;
    /
    
    SELECT /*+PARALLEL(person, 5) */ *
     FROM PERSON
    WHERE LONGCHECKFUNC(ID)=1;
    

    First, you need to add PARALLEL_ENABLE to your function. This tells Oracle that function calls do not share any session data, and can be run independently.

    The second change, adding hash partitioning, I don’t fully understand. It depends on the internal algorithms Oracle uses to divide work loads. When there are hash partitions, it’s probably easiest to divide the segments among the parallel servers. Without partitioning, there is only a small number of blocks, and Oracle probably assumes it will be fastest to run everything on a single parallel server.

    (Even if you use ASSOCIATE STATISTICS and give the function a ridiculous cost, Oracle will still run it serially. Perhaps there is some limitation where Oracle will never split a block among multiple parallel servers?)

    This runs in about 1.1. seconds on my machine. But since it depends on (AFAIK) undocumented behavior, I’m not sure if it will run the same for you. Oracle’s hashing functions do not put values in buckets in a simple round-robin fashion. To minimize collisions, and increase the chance of optimal parallelism, you will need to use a large number of partitions.

    As @David Aldridge mentioned, parallel query is not really designed for this. If you want a more deterministic process, you’ll need something like the solution suggested by @Polppan (use DBMS_SCHEDULER).

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

Sidebar

Related Questions

We have a Single Statement FUNCTION in SQL Server 2005 which uses CONTAINSTABLE(). All
I currently have a prepared statement in Java which uses the following SQL statement
I have the following basic SQL statement which uses the PIVOT command. SELECT *
I have a SQL statement which returns a number of rows and these are
I have the following SQL statement which has a very bad performance: SELECT frmInstLastModifiedDate
I have a fairly large SQL statement which has a number of inner joins
I have a method which includes sql statement . it is public Boolean addRSS(string
I have 3 tables which need to be linked in an SQL statement (I'm
I currently have this statement in my SQL View (SQL Server 2008 R2) which
I have some working code that uses a SQL select statement within it. As

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.