Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query optimization tips needed

883189Nov 26 2015 — edited Nov 26 2015

Hello All,

There is a table around 3TB in size partitioned on date column on month basis like 20151001, 20151101, 20151201 etc.

I would need to get the active counts for each year.Is there a better way of writing the query based on partitions ?

There are many other columns but required are these two only. Date and active columns are defined as number type.

Here is the sample data.

1036501620000131
1036501620100131
1036501920100131
1036505620100131
1036501820130131
1036505620130131
1036502020150130
1036501920150130
1036501920150131
1036501920150131

First column being active, second column is date.

The output should be like below

12000
32010
22013
22015

I wrote the query as below, but the explain plan is pretty bad as it is doing full table scan and the query is running since last 2days.

Can any one provide some suggestions please, this is bit urgent. Please kindly help, let me know if more details are needed.

select count(distinct active),

substr(date,1,4)

from table

group by substr(date,1,4)

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 24 2015
Added on Nov 26 2015
7 comments
1,418 views