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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:28:19+00:00 2026-05-31T16:28:19+00:00

I want to sample data based on a timestamp field. I am reading huge

  • 0

I want to sample data based on a timestamp field. I am reading huge data files, each having close to million record a day. I have several such files for every month.

Now I want to read this data, but store, say, only 5% or 10% into a mysql database. I do not have prior knowledge of number of records in each of the data files.

Is there any way with which I can sample only 5% of total read data for a file? Are there any standard statistical approaches to this kind of problem?

EDIT based on comments below:

Before this sampling idea, I had created a key based partition and index on two fields: id and date. The id field is more like a clientId. Even with partitioning, a group by 2 fields on 15 million rows would take criminally long time, in the range of 30-60 mins. I had also created and additional index on one of the group by field.

My explanation would show this:

SIMPLE visits ref 3ColumnerIndex,2ColumnIndex 2ColumnIndex 302 const 7493642 Using where; Using filesort

Got this performance after giving innodb a buffer size of 4 GB!

  • 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-31T16:28:21+00:00Added an answer on May 31, 2026 at 4:28 pm

    You need an estimate of the number of records for this to work, but if you don’t have strict requirements of how many samples you need this shouldn’t be a problem:

    1. Suppose you are choosing k samples from n records.
    2. For each record, or until you have enough records:
      1. Produce a random number between 0 and 1.
      2. If it is less than k/n, output the current record. Put k := k-1 and n := n-1.
      3. Else, discard the record and put n := n-1.

    Each record appear in the output with probability k/n. E.g. the probability of the second record appearing would be:

    (k/n)*(k-1)/(n-1) + ((n-k)/n)*k/(n-1) = (k-1+n-k)*k/(n*(n-1)) = k/n
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function that allows users to match data based on
I have an input file that I want to sort based on timestamp which
I want to display data based on start date and end date. a code
I'm developing a explorer data provider based on this sample . I already added
I have a simple database named customer with a single table data.I want to
i want to manipulate xml data simple .. thanks
I have a simple WCF Data Services service and I want to expose a
I want to use data binding with an XML document to populate a simple
i have application who use specific process during running and i want to sample
I want to continuously sample from my PC's audio line in using C# (then

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.