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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:11:34+00:00 2026-06-01T02:11:34+00:00

My table: CREATE TABLE `beer`.`matches` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `hashId` int(10)

  • 0

My table:

CREATE TABLE `beer`.`matches` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `hashId` int(10) unsigned NOT NULL,
  `ruleId` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

If a hash has matched a rule, there’s an entry in this table.

1) Count how many hashIds there are for each unique ruleId (AKA “how many hashes matched each rule”)

SELECT COUNT(*), ruleId FROM `beer`.`matches` GROUP BY ruleId ORDER BY COUNT(*)

2) Select the 10 best rules (ruleIds), that is, select the 10 rules that combined matches the greatest number of unique hashes. This means that a rule that matches a lot of hashes is not neccessarily a good rule, if another rule covers all the same hashes. Basically I want to select the 10 ruleIds that catches the most unique hashIds.

?

EDIT: Basically I have a sub-optimal solution in PHP/SQL here, but depending on the data it doesn’t necessarily give me the best answer to question 2). I’d be interested in a better solution. Read the comments for more information.

  • 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-01T02:11:35+00:00Added an answer on June 1, 2026 at 2:11 am

    If you really want to find the best solution (optimal solution), the problem is that you have to check all the possible combinations of 10 ruleIds, and find how many hashIds are returned by each of this possible combination. The problem is that the number of combinations is grossly the different number of ruleids ^ 10 (in fact, the number is smaller, if you consider that you cannot repeat the same ruleIds in the combinations… its a combination of m elements taken in groups of 10).

    • NOTE: To be exact, the number of possible combinations is

      m!/(n!(m-n)!) => m!/(10!(m-10!)) where ! is factorial: m! = m * m-1 * m-2… * 3 * 2 * 1

    To do this combinations you have to join your table with itself, 10 times, excluding the previous combinations of ruleids, somewhat like this:

    select m1.ruleid r1, m2.ruleid r2, m3.ruleid r3 ...
    from matches m1 inner join matches m2 on m2<>m1 
       inner join matches m3 on m3 <> m1 and m3 <> m2
         ...
    

    Then you have to find the highest count of

    select r1, r2, r3..., count(distinct hashid) 
    from ("here the combinations of 10 ruleIds define above") G10
    inner join M
      on ruleid = r1 or ruleid = r2 or ruleid=r3...
    group by r1, r2, r3...
    

    This gigantic query would take a lot of time to run.

    There can be much faster procedures that will give you sub-optimal results.

    SOME OPTIMIZATION:

    This could be somewhat optimized, depending on the data shape, looking for groups which are equal to or included in other groups. This would require less than (m*(m+1))/2 operations, which compared to the other number, it’s a big deal, specially if it’s quite probable to find several groups which can be discarded, which will lower m. Anyway, the main has still a gigantic cost.

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

Sidebar

Related Questions

I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have a table: CREATE TABLE `data_table` ( `data_id` INT NOT NULL AUTO_INCREMENT PRIMARY
I've got MySQL table CREATE TABLE cms_webstat ( ID int NOT NULL auto_increment PRIMARY
Create Table: CREATE TABLE `category` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255)
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
I have this table: CREATE TABLE `point` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `siteid`
I Have the following table: CREATE TABLE `tmp_table` ( `id` int(11) NOT NULL AUTO_INCREMENT,
Here's my table: CREATE TABLE `alums_alumphoto` ( `id` int(11) NOT NULL auto_increment, `alum_id` int(11)
I have the following table: CREATE TABLE `events` ( `evt_id` int(11) NOT NULL AUTO_INCREMENT,
I have this table: CREATE TABLE `search_engine_rankings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `keyword_id`

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.