Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count from USER_INDEXES and ALL_INDEXES

Tags:

oracle

I was trying to execute the following query to get the count of index from my schema.

select count(*) from USER_INDEXES; --which gave me a count of 397

But select count(*) from ALL_INDEXES where table_owner ='MY_SCHEMA'; -- gave me 357.

What it sounds? Both should be same right?

When checked from Oracle SQL developer by counting the indexes myself, gave me 397

like image 279
Nidheesh Avatar asked Jan 24 '14 03:01

Nidheesh


People also ask

Why can't I see the lob Index in user_indexes view?

@jonearles : Yes.It is correct. I double-checked that. This is because, the view ALL_INDEXES contains all the indexes the current user has the ability to modify. You will not see the LOB index in this view because LOB indexes cannot be renamed, rebuilt, or modified. While USER_INDEXES view contains all the indexes that the user owns.

How to gather information about all indexes in a specific database?

In order to gather information about all indexes in a specific database, you need to execute the sp_helpindex number of time equal to the number of tables in your database. For the previously created database that has three tables, we need to execute the sp_helpindex three times as shown below: sp_helpindex ' [dbo]. [STD_Evaluation]'

Is it correct to use all_indexes instead of user_ indexes?

When checked from Oracle SQL developer by counting the indexes myself, gave me 397 Are you sure those numbers are correct? They look backwards to me. I would expect ALL_INDEXES to return more than USER_INDEXES. @jonearles : Yes.It is correct. I double-checked that.

Why do we have so many indexes in SQL Server?

This huge number of allowed, but not recommended, indexes help us in covering and enhancing the performance of a large number of queries that try to retrieve data from the database table.


1 Answers

This is because, the view ALL_INDEXES contains all the indexes the current user has the ability to modify. You will not see the LOB index in this view because LOB indexes cannot be renamed, rebuilt, or modified.

While USER_INDEXES view contains all the indexes that the user owns. The LOB index will be in this view if the user querying it is the same user that created it.

like image 129
Dba Avatar answered Sep 23 '22 14:09

Dba