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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:22:41+00:00 2026-05-16T21:22:41+00:00

My object model is given below and would like your inputs on the number

  • 0

My object model is given below and would like your inputs on the number of indexes to create for faster query responses (on h2, mysql). Assumptions and questions are given below the following model.

@Entity
@Table(name = "user")
public class User  {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @ForeignKey(name = "fk_user_org_id")
    @Index(name = "idx_user_org_id")
    @JoinColumn(name = "org_id", nullable = false, referencedColumnName = "id")
    @NotNull
    private Organization organization;

    @ManyToOne(fetch = FetchType.LAZY)
    @ForeignKey(name = "fk_user_year_id")
    @Index(name = "idx_user_year_id")
    @JoinColumn(name = "year", nullable = false, referencedColumnName = "id")
    @NotNull
    private Year year;

    @ManyToOne(fetch = FetchType.LAZY)
    @ForeignKey(name = "fk_user_created_by")
    @Index(name = "idx_user_created_by")
    @JoinColumn(name = "created_by", nullable = false, referencedColumnName = "id")
    @NotNull
    private User createdBy;

    @Column(name = "name", nullable = false)
    private String name;

    @Column(name = "desc")
    private String desc;

    @Column(name = "is_system", length = LEN_1)
    @Type(type = "org.hibernate.type.YesNoType")
    private boolean isSystem = false;

    @Column(name = "user_type", nullable = false)
    private UserType userType;

    @Column(name = "status", nullable = false)
    @NotNull
    private Status status;

}

Our plan is to use multi column indexes instead of a single column index (i.e. create index user_idx based on (organization, year, isSystem, status, userType, createdBy)). Assuming I have this index, will I get optimized responses for my queries listed below.

  1. select * from user where organization=1 and year=2010;
  2. select * from user where organization=1 and year=2010 and isSytem=true or false; (i.e. system users or application defined users)
  3. select * from user where organization=1 and year=2010 and isSytem=false and userType=Manager (i.e. all managers)
  4. select * from user where organization=1 and year=2010 and isSytem=false and userType=Employee (i.e. all employees)
  5. select * from user where organization=1 and year=2010 and isSytem=false and userType=Manager and status=ACTIVE (i.e. Active users)
  6. select * from user where organization=1 and year=2010 and createdBy=’Sam’ or ‘Joe’
    Does [6] need a different multi column index, consisting of the above 3 columns?

  7. Since we are creating a multi column index as per my original assumption, can I safely remove the individual indexes (idx_user_org_id, idx_user_year_id, idx_user_created_by) as currently defined in the model?

  • 1 1 Answer
  • 3 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-16T21:22:42+00:00Added an answer on May 16, 2026 at 9:22 pm

    You should switch the order of the columns in your index:

    (organization, year, isSystem, userType, status, createdBy)
    

    This allows it to better serve these two queries:

    select * from user where organization=1 and year=2010 and isSystem=false and userType=Manager
    select * from user where organization=1 and year=2010 and isSystem=false and userType=Employee
    

    Does [6] need a different multi column index, consisting of the above 3 columns?

    It doesn’t need a new index – it can use the existing one but in a less efficient way – only the first two columns will be used. Adding a new index for this query looks like a good idea though.

    can I safely remove the individual indexes

    Yes. You should remove unused indexes otherwise they will just take up disk space and slow down table modifications without providing any benefit.

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

Sidebar

Related Questions

I am looking to replicate a given object function across various model files As
Given the below model and view, for any given club I am trying to
For the given mock object below, how can I check if the WashCar(ICar car)
Given the following view : def comments(request): comments_list = Thing.objects.filter(thing_type=2) #Thing model extends MPTTModel
Consider the Following object model (->> indicates collection): Customer->Orders Orders->>OrderLineItems->Product{Price} The app is focused
I am currently reading Inside the C++ Object Model. On page 9 it has
I have a project which exposes object model to use by different types of
Hi I'm have an object model with an Employee and EmployeeWorksiteReference (cause it's an
I'm using XmlSerializer to serialize my object model to XML. At the moment just
I've created a class library which exposes my back-end object model. I don't wish

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.