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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:01:01+00:00 2026-05-31T21:01:01+00:00

First, a simple example to describe my problem. Model public class User { public

  • 0

First, a simple example to describe my problem.

Model

public class User
{
    public virtual String UserID { get; set; }
    public virtual String UserName { get; set; }
    public virtual DateTime LastLoginTime { get; set; }
}

Mapping

<id name="UserID" type="AnsiString">
  <column name="p_UserID_vc" length="20"></column>
  <generator class="assigned"/>
</id>
<property name="UserName" column="UserName_vc"  type="AnsiString">
<property name="LastLoginTime" column="LastLoginTime_d" type="DateTime">

table

create table T_User
(
    p_userid_vc         VARCHAR2(20) not null,
    username_vc         VARCHAR2(50),
    lastlogintime_d     DATE,
)

Now ,there are one million users in this table. I create a oracle index in LastLoginTime. I use query like this:

var list = Responsity<User>.Where(q => q.LastLoginTime <= DateTime.Now &&   
           q.LastLoginTime >= DateTime.Now.AddDays(-7));           

I use Nhibernate Profile to watchout the real sql string:

select t.p_UserID_vc
  from T_User t
 where t.lastlogintime_d >= TIMESTAMP '2012-03-19 16:58:32.00' /* :p1 */
   and t.lastlogintime_d <= TIMESTAMP '2012-03-26 16:58:32.00' /* :p2 */

It didn’t use the index. I think it should use ‘to_date’ ,so that it could use the index. How to config the mapping file?

  • 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-31T21:01:02+00:00Added an answer on May 31, 2026 at 9:01 pm

    There are a few reasons why it might not be using your index:

    1. The datatype of LastLoginTime is a DATE, but the parameters are TIMESTAMPs, so it might be implicitly converting the column to a timestamp, which would mean it cannot use the index.

    2. The Cost-Based-Optimizer (CBO) might be using statistics which indicate that using the index would be less efficient than not using it. For example, there might be very few rows in the table, or a histogram might tell the CBO that a large number of rows match the date range you’re querying on. It’s not uncommon for full table scans to outperform queries that use indexes.

    3. Perhaps the statistics on the table are out-of-date, causing the CBO to make inaccurate estimates.

    Do an explain plan on your query to determine what the cause is.

    Note: the plan for a query that uses literal values (e.g. TIMESTAMP '...') could very well be different to that for a query that uses bind variables (e.g. p1 and p2). Run the explain plan for the query that is actually being executed.

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

Sidebar

Related Questions

To describe my dilemma, let me first start with an example problem (stolen from
My first try of MVC. Am trying to implement a simple example. Inspiration from
I have a simple marker annotation for methods (similar to the first example in
I have a simple question related to one-line programming. First an example: function test(a)
very \n simple example of big => return true because first occurrence moving backwards
I'm on the final stretch of my first simple iPhone application. I'm building an
http://dspace.dial.pipex.com/town/green/gfd34/art/bloopers.html The first one seems simple; return strcpy(malloc(strlen(s)), s); malloc could return null ,
I'm implementing the specification pattern. The NotSpecification seems simple at first: NotSpecification.IsSpecialCaseOf(otherSpecification) return !this.specification.isSpecialCaseOf(otherSpecification)
Can anyone explain in simple words what First and Second Level caching in Hibernate/NHibernate
First of all, I wrote a simple php page, that picks up some variables

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.