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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:47:39+00:00 2026-06-11T15:47:39+00:00

I am auditing user details from my application using open Id login .If a

  • 0

I am auditing user details from my application using open Id login .If a first time a user is login a OPEN ID we consider as signup . I am generating audit signin report using this details . Sample Table Data.

+---------+----------+-----------+---------------+
| USER_ID | PROVIDER | OPERATION | TIMESTAMP     |
+---------+----------+-----------+---------------+
|     120 | Google   | SIGN_UP   | 1347296347000 |
|     120 | Google   | SIGN_IN   | 1347296347000 |
|     121 | Yahoo    | SIGN_IN   | 1347296347000 |
|     122 | Yahoo    | SIGN_IN   | 1347296347000 |
|     120 | Google   | SIGN_UP   | 1347296347000 |
|     120 | FaceBook | SIGN_IN   | 1347296347000 |
+---------+----------+-----------+---------------+

In this table I want to exclude already SIGN_UP ed “SIGN_IN” ed user count based on provider .

Show Create table

CREATE TABLE `signin_details` (
  `USER_ID` int(11) DEFAULT NULL,
  `PROVIDER` char(40) DEFAULT NULL,
  `OPERATION` char(40) DEFAULT NULL,
  `TIMESTAMP` bigint(20) DEFAULT NULL
) ENGINE=InnoDB

I am using this query .

select 
  count(distinct(USER_ID)) as signin_count, 
  PROVIDER from signin_details s1 
where 
  s1.USER_ID NOT IN 
  (
    select 
      USER_ID 
    from signin_details 
    where 
      signin_details.PROVIDER=s1.PROVIDER 
      and signin_details.OPERATION='SIGN_UP' 
      and signin_details.TIMESTAMP/1000 BETWEEN UNIX_TIMESTAMP(CURRENT_DATE()-INTERVAL 1 DAY) * 1000 AND UNIX_TIMESTAMP(CURRENT_DATE()) * 1000
  )  
  AND OPERATION='SIGN_IN' group by PROVIDER;

Explain Output:

+----+--------------------+----------------+------+---------------+------+---------+------+------+-----------------------------+
| id | select_type        | table          | type | possible_keys | key  | key_len | ref  | rows | Extra                       |
+----+--------------------+----------------+------+---------------+------+---------+------+------+-----------------------------+
|  1 | PRIMARY            | s1             | ALL  | NULL          | NULL | NULL    | NULL |    6 | Using where; Using filesort |
|  2 | DEPENDENT SUBQUERY | signin_details | ALL  | NULL          | NULL | NULL    | NULL |    6 | Using where                 |
+----+--------------------+----------------+------+---------------+------+---------+------+------+-----------------------------+

Query Output :

+--------------+----------+
| signin_count | PROVIDER |
+--------------+----------+
|            1 | FaceBook |
|            2 | Yahoo    |
+--------------+----------+

It takes more than 40 minutes to execute for 200k rows.

My assumption is it will check each row with total number of dependant subquery output.

My Assumption on this query.

 A -> Dependant Outputs (B,C,D) .
 A check with B
 A check with C
 A check with D

If dependant query output is larger it will take so long time to execute. How to improve this query?

  • 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-06-11T15:47:40+00:00Added an answer on June 11, 2026 at 3:47 pm

    If you use MySQL you have to know that sub queries performs awful slow.

    IN is slow…

    EXISTS is often faster then IN

    JOIN is mostly the fastest way do things like this.

    SELECT DISTINCT
      s1.PROVIDER,
      COUNT(DISTINCT s1.USER_ID)
    
    FROM 
      signin_details s1
      LEFT JOIN 
      (
        SELECT DISTINCT
          USER_ID, PROVIDER
        FROM 
          signin_details 
        WHERE
          signin_details.OPERATION='SIGN_UP' 
          AND 
            signin_details.TIMESTAMP 
              BETWEEN 
                UNIX_TIMESTAMP(CURRENT_DATE()-INTERVAL 1 DAY) * 1000 
                AND UNIX_TIMESTAMP(CURRENT_DATE()) * 1000
      ) AS t USING  (USER_ID, PROVIDER)
    
    WHERE
      t.USER_ID IS NULL
      AND OPERATION='SIGN_IN'
    GROUP BY s1.PROVIDER
    

    http://sqlfiddle.com/#!2/122ac/12

    NOTE: If you wonder about the sqlfiddle result consider here is a UNIX_TIMESTAMP in the query.

    Result:

    | PROVIDER | COUNT(DISTINCT S1.USER_ID) |
    -----------------------------------------
    | FaceBook |                          1 |
    |    Yahoo |                          2 |
    

    MySQL and the INTERSECT story. You get all combinations of USER_ID and PROVIDER which you don’t want to count. Then LEFT JOIN them to your data. Now all the rows you want to count have no values from the LEFT JOIN. You get them by t.USER_ID IS NULL.


    Input:

    | rn° | USER_ID | PROVIDER | OPERATION |     TIMESTAMP |
    -------------------------------------------------------
    | 1   |     120 |   Google |   SIGN_UP | 1347296347000 | -
    | 2   |     120 |   Google |   SIGN_IN | 1347296347000 | - (see rn° 1)
    | 3   |     121 |    Yahoo |   SIGN_IN | 1347296347000 | Y
    | 4   |     122 |    Yahoo |   SIGN_IN | 1347296347000 | Y
    | 5   |     120 |   Google |   SIGN_UP | 1347296347000 | -
    | 6   |     120 | FaceBook |   SIGN_IN | 1347296347000 | F
    | 7   |     119 | FaceBook |   SIGN_IN | 1347296347000 | - (see rn° 8)
    | 8   |     119 | FaceBook |   SIGN_UP | 1347296347000 | -
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user model that has_one membership (active at a time). For auditing
I am auditing C code that has been generated from Pro*C ages ago, and
I already audit authorization success, failure and logout. I've considered auditing (logging) every method
My program needs to start auditing saved XML data for users. Whenever the user
We recently added auditing to our database. A colleague implemented it using triggers and
we are about to start using EventLog as our Centralized Auditing solution. A problem
I'm trying to implement basic auditing for a system where users can login, change
Im using collectiveidea's audited solution for auditing in rails. So, there's a column (audited_changes)
I have a trigger for auditing purposes that requires the presence of the audit
I do not want Auditing or History tracking. I have an application that pulls

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.