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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:02:15+00:00 2026-06-04T08:02:15+00:00

I have recently written a survey application that has done it’s job and all

  • 0

I have recently written a survey application that has done it’s job and all the data is gathered. Now i have to analyze the data and i’m having some time issues.
I have to find out how many people selected what option and display it all.

I’m using this query, which does do it’s job:

SELECT COUNT(*)
  FROM survey
 WHERE users = ? AND table = ? AND col = ? AND row = ? AND selected = ?
 GROUP BY users,table,col,row,selected

As evident by the “?” i’m using MySQLi (in php) to fetch the data when needed, but i fear this is causing it to be so slow.

The table consists of all the elements above (+ an unique ID) and all of them are integers.
To explain some of the fields:
Each survey was divided into 3 or 4 tables (sized from 2×3 to 5×5) with a 1 to 10 happiness grade to select form. (questions are on the right and top of the table, then you answer where the questions intersect)

users – age groups

table, row, col – explained above

selected – dooooh explained above

Now with the surveys complete and around 1 million entries in the table the query is getting very slow. Sometimes it takes like 3 minutes, sometimes (i guess) the time limit expires and you get no data at all. I also don’t have access to the full database, just my empty “testing” one since the costumer is kinda paranoid :S (and his server seems to be a bit slow)

Now (after the initial essay) my questions are: I left indexing out intentionally because with a lot of data being written during the survey, it would be a bad idea. But since no new data is coming in at this point, would it make sense to index all the fields of a table? How much sense does it make to index integers that never go above 10? (as you can guess i haven’t got a clue about indexes). Do i need the primary unique ID in this table? I

I read somewhere that indexing may help groups but only if you group by the first columns in a table (and since my ID is first and from my point of view useless can i remove it and gain anything by it?)

Is there another way to write my query that would basically do the same thing but in a shorter period of time?

Thanks for all your suggestions in advance!

  • 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-04T08:02:16+00:00Added an answer on June 4, 2026 at 8:02 am

    Add an index on entries that you “GROUP BY” or do “WHERE”. So that’s ONE index incorporating users,table,col,row and selected in your case.

    Some quick rules:

    • combine fields to have the WHERE first, and the GROUP BY elements last.
    • If you have other queries that only use part of it (e.g. users,table,col and selected) then leave the missing value (row, in this example) last.

    Don’t use too many indexes/indeces, as each will slow the table to updates marginally – so on really large system you need to balance queries with indexes.


    Edit: do you need the GROUP BY user,col,row as these are used in the WHERE. If the WHERE has already filtered them out, you only need group by “selected”.

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

Sidebar

Related Questions

I have recently written an application(vb.net) that stores and allows searching for old council
I have recently inherited a J2EE Struts web app that was written back in
I have recently written some complex ruby script that eventually fails with segfaults in
We have a recently internationalised application written in classic ASP. The following code replicates
I have a PHP application that is written with Zend Framework. It uses Phing
I have recently written an application on per-contract base for a company. The deal
Ok, recently i have written a paint application in Java. Small program similar to
I have recently written a socket server in PHP that will be handling communication
I have recently started work on a project that has already been running for
So I've recently written an application that calculates tip and I wanted to implement

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.