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

  • SEARCH
  • Home
  • 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 7012153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:13:08+00:00 2026-05-27T22:13:08+00:00

I am doing two queries SELECT * FROM datedim WHERE year = YEAR(now()); and

  • 0

I am doing two queries

SELECT * FROM datedim WHERE year = YEAR(now());

and

SELECT * FROM datedim WHERE year = YEAR(getNow());

Here getNow() function just returns NOW();

My problem is that the first one is immediate while the second one take much longer. (1.xx sec)

When I execute the explain command I have this for the first one (which is good)

+----+-------------+---------+------+---------------+-------------+---------+-------+------+-------------+
| id | select_type | table   | type | possible_keys | key         | key_len | ref   | rows | Extra       |
+----+-------------+---------+------+---------------+-------------+---------+-------+------+-------------+
|  1 | SIMPLE      | datedim | ref  | dd_year_idx   | dd_year_idx | 5       | const |  365 | Using where |
+----+-------------+---------+------+---------------+-------------+---------+-------+------+-------------+

But this for the second one (which is pretty bad)

+----+-------------+---------+------+---------------+------+---------+------+-------+-------------+
| id | select_type | table   | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
+----+-------------+---------+------+---------------+------+---------+------+-------+-------------+
|  1 | SIMPLE      | datedim | ALL  | NULL          | NULL | NULL    | NULL | 10958 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+-------+-------------+

Can someone explain me what is happening and why doing the same thing, looking for all date with year that is the same to NOW(), takes much longer when using a function than giving it straight.

This example is simple but later my function will return a specific date, I would like just to understand what is happening.

  • 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-27T22:13:08+00:00Added an answer on May 27, 2026 at 10:13 pm

    MySQL seems to execute the getNow() function for each row, NOW() is executed only once per statement:

    NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.) This differs from the behavior for SYSDATE(), which returns the exact time at which it executes.

    But you can change your query to the following to have the same effect:

    SELECT *
    FROM datedim
    JOIN (SELECT YEAR(getNow()) as `year`) as y
    USING (`year`);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have two tables that I am joining and doing a select on
I have a SQL query that I'm currently solving by doing two queries. I
Here total two union binding three queries, first query retrieving records from a virtual
I'm trying to combine these two select queries but the count function is confusing
I doing a function in Javascript like the VisualBasic DateDiff. You give two dates
I have two queries, the only difference being the GROUP BY clause SELECT *
What I ended up doing was taking two SQL queries and using the array_intersect()
I have two queries that produce the same output. One is using the Intersect
I have compared two queries which fetch some fairly large data from a database
I am trying to profile two different queries that do the same thing to

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.