SELECT 
  SQL_CALC_FOUND_ROWS products.product_id, 
  descr1.product as product, 
  companies.company as company_name, 
  products.product_type, 
  products.parent_product_id 
FROM 
  q_products as products 
  LEFT JOIN q_product_options_inventory as inventory ON inventory.product_id = products.product_id 
  LEFT JOIN q_product_descriptions as descr1 ON descr1.product_id = products.product_id 
  AND descr1.lang_code = 'en' 
  LEFT JOIN q_product_prices as prices ON prices.product_id = products.product_id 
  AND prices.lower_limit = 1 
  LEFT JOIN q_companies AS companies ON companies.company_id = products.company_id 
  INNER JOIN q_products_categories as products_categories ON products_categories.product_id = products.product_id 
  INNER JOIN q_categories ON q_categories.category_id = products_categories.category_id 
  AND (
    q_categories.usergroup_ids = '' 
    OR FIND_IN_SET(0, q_categories.usergroup_ids) 
    OR FIND_IN_SET(1, q_categories.usergroup_ids)
  ) 
  AND q_categories.status IN ('A', 'H') 
WHERE 
  1 
  AND companies.status = 'A' 
  AND products.company_id = 173 
  AND (
    CASE products.tracking WHEN 'O' THEN inventory.amount > 0 WHEN 'B' THEN products.amount > 0 ELSE 1 END
  ) 
  AND (
    products.usergroup_ids = '' 
    OR FIND_IN_SET(0, products.usergroup_ids) 
    OR FIND_IN_SET(1, products.usergroup_ids)
  ) 
  AND products.status IN ('A') 
  AND prices.usergroup_id IN (0, 0, 1) 
  AND products.company_id = 173 
  AND products.parent_product_id = 0 
GROUP BY 
  products.product_id 
ORDER BY 
  products.timestamp desc, 
  products.product_id ASC 
LIMIT 
  128, 128

Query time 0.13192

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "7419.44"
    },
    "ordering_operation": {
      "using_filesort": true,
      "grouping_operation": {
        "using_temporary_table": true,
        "using_filesort": false,
        "nested_loop": [
          {
            "table": {
              "table_name": "inventory",
              "access_type": "system",
              "possible_keys": [
                "pc"
              ],
              "rows_examined_per_scan": 0,
              "rows_produced_per_join": 1,
              "filtered": "0.00",
              "const_row_not_found": true,
              "cost_info": {
                "read_cost": "0.00",
                "eval_cost": "0.20",
                "prefix_cost": "0.00",
                "data_read_per_join": "976"
              },
              "used_columns": [
                "product_id",
                "amount"
              ]
            }
          },
          {
            "table": {
              "table_name": "companies",
              "access_type": "const",
              "possible_keys": [
                "PRIMARY"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "company_id"
              ],
              "key_length": "4",
              "ref": [
                "const"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 1,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "0.00",
                "eval_cost": "0.20",
                "prefix_cost": "0.00",
                "data_read_per_join": "5K"
              },
              "used_columns": [
                "company_id",
                "status",
                "company"
              ]
            }
          },
          {
            "table": {
              "table_name": "products_categories",
              "access_type": "index",
              "possible_keys": [
                "PRIMARY",
                "pt"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "category_id",
                "product_id"
              ],
              "key_length": "6",
              "rows_examined_per_scan": 15659,
              "rows_produced_per_join": 15659,
              "filtered": "100.00",
              "using_index": true,
              "cost_info": {
                "read_cost": "140.59",
                "eval_cost": "3131.80",
                "prefix_cost": "3272.39",
                "data_read_per_join": "244K"
              },
              "used_columns": [
                "product_id",
                "category_id"
              ]
            }
          },
          {
            "table": {
              "table_name": "q_categories",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "c_status",
                "p_category_id"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "category_id"
              ],
              "key_length": "3",
              "ref": [
                "portal.products_categories.category_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 3131,
              "filtered": "20.00",
              "cost_info": {
                "read_cost": "0.00",
                "eval_cost": "626.36",
                "prefix_cost": "6404.19",
                "data_read_per_join": "8M"
              },
              "used_columns": [
                "category_id",
                "usergroup_ids",
                "status"
              ],
              "attached_condition": "(((`portal`.`q_categories`.`usergroup_ids` = '') or find_in_set(0,`portal`.`q_categories`.`usergroup_ids`) or find_in_set(1,`portal`.`q_categories`.`usergroup_ids`)) and (`portal`.`q_categories`.`status` in ('A','H')))"
            }
          },
          {
            "table": {
              "table_name": "products",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "status",
                "idx_parent_product_id"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "portal.products_categories.product_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 277,
              "filtered": "8.87",
              "cost_info": {
                "read_cost": "0.00",
                "eval_cost": "55.56",
                "prefix_cost": "7030.55",
                "data_read_per_join": "1M"
              },
              "used_columns": [
                "product_id",
                "product_type",
                "status",
                "company_id",
                "amount",
                "timestamp",
                "usergroup_ids",
                "tracking",
                "parent_product_id"
              ],
              "attached_condition": "((`portal`.`products`.`parent_product_id` = 0) and (`portal`.`products`.`company_id` = 173) and (case `portal`.`products`.`tracking` when 'O' then <cache>((NULL > 0)) when 'B' then (`portal`.`products`.`amount` > 0) else 1 end) and ((`portal`.`products`.`usergroup_ids` = '') or find_in_set(0,`portal`.`products`.`usergroup_ids`) or find_in_set(1,`portal`.`products`.`usergroup_ids`)) and (`portal`.`products`.`status` = 'A'))"
            }
          },
          {
            "table": {
              "table_name": "descr1",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "product_id"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "product_id",
                "lang_code"
              ],
              "key_length": "9",
              "ref": [
                "portal.products_categories.product_id",
                "const"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 277,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "0.00",
                "eval_cost": "55.56",
                "prefix_cost": "7086.11",
                "data_read_per_join": "1M"
              },
              "used_columns": [
                "product_id",
                "lang_code",
                "product"
              ]
            }
          },
          {
            "table": {
              "table_name": "prices",
              "access_type": "ref",
              "possible_keys": [
                "usergroup",
                "product_id",
                "lower_limit",
                "usergroup_id"
              ],
              "key": "usergroup",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "portal.products_categories.product_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 277,
              "filtered": "99.95",
              "using_index": true,
              "cost_info": {
                "read_cost": "277.78",
                "eval_cost": "55.53",
                "prefix_cost": "7419.44",
                "data_read_per_join": "6K"
              },
              "used_columns": [
                "product_id",
                "lower_limit",
                "usergroup_id"
              ],
              "attached_condition": "((`portal`.`prices`.`lower_limit` = 1) and (`portal`.`prices`.`usergroup_id` in (0,0,1)))"
            }
          }
        ]
      }
    }
  }
}

Result

product_id product company_name product_type parent_product_id
47678 Bestway H2Ogo 91Cm X 63Cm X 1.63M Hydro Hoopz, 52216E Pronto Trading L.L.C. P 0
47679 Bestway Children's Inflatable Helicopter Ball Pit, Includes 50 Balls (BW52217) Pronto Trading L.L.C. P 0
47680 Bestway 1.12Mx99Cmx97Cm Covered Hippo Baby Pool, 52218 Pronto Trading L.L.C. P 0
47681 Bestway 1.09M X 96Cm X 1.04M Turtle Totz Play Pl, 52219 Pronto Trading L.L.C. P 0
47682 Bestway - 52220 Baby Animal Rocker Multi Color Pronto Trading L.L.C. P 0
47683 Bestway 1.09Mx1.04M Baby Play Pen, 52221 Pronto Trading L.L.C. P 0
47684 Bestway 91Cm X51Cm Bonk Outs, 52222 Pronto Trading L.L.C. P 0
47685 Bestway 18'/5.49M Led Landing Splash & Slide, 52226 Pronto Trading L.L.C. P 0
47686 Bestway 1.30Mx33Cmx33Cm Bonk Outs Sticks, 52227E Pronto Trading L.L.C. P 0
47688 Bestway 1.75Mx71Cm X1.50 Limber Limbo Sprinkler, 52238 Pronto Trading L.L.C. P 0
47690 Bestway Inflatable Animals Play Mat Pronto Trading L.L.C. P 0
47691 Bestway 81Cm X 63Cm X 46Cm Changing Mat, 52241 Pronto Trading L.L.C. P 0
47692 Bestway 21Cm X 10Cm Catch And Throw Set, 52244 Pronto Trading L.L.C. P 0
47693 Bestway H2Ogo 18Ft/5.49M Slime Blast Slide, 52251 Pronto Trading L.L.C. P 0
47694 Bestway H2Ogo 18'/5.49Mtrs Double Slide, 52255 Pronto Trading L.L.C. P 0
47695 Bestway 1.80Mx H86Cm Bouncejam Bouncer, 52262 Pronto Trading L.L.C. P 0
47696 Bestway 89Cmx86Cmx1.07M Jungletime Ball Pit, 52266 Pronto Trading L.L.C. P 0
47697 Bestway 1.42Mx1.37Mx1.14M Octopus Bouncer, 52267 Pronto Trading L.L.C. P 0
47698 Bestway 1.22Mx84Cmx84Cm Scoops N Smile Icecream, 52268 Pronto Trading L.L.C. P 0
47699 Bestway Up, In And Over Inflatable Bouncy Castle Hot Air Balloon Pronto Trading L.L.C. P 0
47700 Bestway 91Cmx91Cmx89Cm Candyville Playtime Pool, 52270 Pronto Trading L.L.C. P 0
47701 Bestway 1.93M X 1.5M X 89Cm Play Center, 53026 Pronto Trading L.L.C. P 0
47702 Bestway 80"X65"X29" Viking Play Pool, 53033 Pronto Trading L.L.C. P 0
47703 Bestway 1.9M X 1.4M X 96Cm Pirate Play Pool, 53041 Pronto Trading L.L.C. P 0
47705 Bestway 1.52M X 74Cm 3Ring Elephant Spalsh Pool, 53048 Pronto Trading L.L.C. P 0
47706 Bestway 2.01M X 2.01M X 91Cm Hippo Play Pool, 53050 Pronto Trading L.L.C. P 0
47707 Bestway 2.79Mx1.73Mx1.02M Interactive Play Pool, 53051 Pronto Trading L.L.C. P 0
47708 Bestway 2.39M X 2.06M X86Cm Fantastic Aquarium, 53052 Pronto Trading L.L.C. P 0
47709 Bestway 2.11M X 1.55M X 81Cm Play & Grow Pool, 53055 Pronto Trading L.L.C. P 0
47710 Bestway 2.36Mx1.98Mx1.40M Shark Attack Play Pool, 53056E Pronto Trading L.L.C. P 0
47711 Bestway 2.31M X 1.93M X 1.50M Undersea Pool Play, 53057 Pronto Trading L.L.C. P 0
47712 Bestway 3.38M X 1.67M X 1.29M Zoo Pool Play, 53060 Pronto Trading L.L.C. P 0
47714 Bestway 2.77Mx1.75Mx1.50M Volcano Splash Island, 53063 Pronto Trading L.L.C. P 0
47719 Bestway 4.35Mx2.13Mx1.17M Lil Champ Play Center, 53068 Pronto Trading L.L.C. P 0
47720 Bestway 2.65Mx2.65Mx1.04M Lava Lagoon Play Cntr, 53069 Pronto Trading L.L.C. P 0
47721 Bestway 1.70Mx1.37Mx53Cm Cannon Catapult Pool, 53070 Pronto Trading L.L.C. P 0
47722 Bestway H2Ogo 3.65Mx3.20Mx2.70M Turbo Splash, 53301 Pronto Trading L.L.C. P 0
47725 Bestway H2Ogo 6.62Mx3.01Mx1.50M Splash & Dash, 53343 Pronto Trading L.L.C. P 0
47730 Bestway 79"X59"X20" Blue Rectangular Family Pool, 54005 Pronto Trading L.L.C. P 0
47731 Bestway 8.5"X69"X20" Blue Rectangular Fmly Pool, 54006 Pronto Trading L.L.C. P 0
47732 Bestway 10"X72"X22" Dlx Blu Rectangular Fmly Pol, 54009 Pronto Trading L.L.C. P 0
47733 Bestway 2.29Mx1.52Mx51Cm Elliptic Pool, 54066 Pronto Trading L.L.C. P 0
47734 Bestway 103"X69"X20" Interactive 3D Adventure, 54114 Pronto Trading L.L.C. P 0
47735 Bestway 99"X99"X20" Dlx Octagon Family Pool, 54119 Pronto Trading L.L.C. P 0
47736 Bestway 90"X60"X22" Play Pool, 54120 Pronto Trading L.L.C. P 0
47737 Bestway 3.05Mx1.83Mx56Cm Play Pool, 54121 Pronto Trading L.L.C. P 0
47738 Bestway 2.54M X 1.68M X 1.02 Beasketball Play Pl, 54122 Pronto Trading L.L.C. P 0
47739 Bestway 3.05Mx1.83M X56Cm H2Ogo! Family Funpool, 54134E Pronto Trading L.L.C. P 0
47740 Bestway 3.05M X 1.83M X 46Cm Blue Rectangular Pl, 54150 Pronto Trading L.L.C. P 0
47741 Bestway 2.13Mx2.06Mx69Cm Family Fun Pool, 54153 Pronto Trading L.L.C. P 0
47742 Bestway 2.32M X 2.29M X 63Cm Family Fundaylounge, 54158 Pronto Trading L.L.C. P 0
47743 Bestway 2.79Mx2.34Mx48Cm Staycation Pool, 54168 Pronto Trading L.L.C. P 0
47744 Bestway 2.37Mx1.52Mx94Cm Skill Shot Play Pool, 54170 Pronto Trading L.L.C. P 0
47745 Bestway 2.62Mx1.75Mx51Cm 3D Undersea Adventure P, 54177 Pronto Trading L.L.C. P 0
47746 Bestway 48"X10' Fill N Full Pool, 55028 Pronto Trading L.L.C. P 0
47747 Bestway 72"X15" Fill N Fun Pool, 55030 Pronto Trading L.L.C. P 0
47748 Bestway 96"X18" Fill N Fun Pool, 55031 Pronto Trading L.L.C. P 0
47749 Bestway 4.57M X 91Cm(15'X36")Steel Pro Frame, 56017 Pronto Trading L.L.C. P 0
47750 Bestway 5"X15 My First Fast Pool Set, 57241 Pronto Trading L.L.C. P 0
47751 Bestway Flowclear 2.62Mx1.75Mx51Cm Pool Cover, 58319 Pronto Trading L.L.C. P 0
47752 Bestway 1.96M X 1.14M Battle Bomber Raft, 61108 Pronto Trading L.L.C. P 0
47753 Bestway 12/30Cm Air Hammer Inflation Pump, 62002 Pronto Trading L.L.C. P 0
47754 Bestway 14/36Cm Air Hammer Inflation Pump, 62003 Pronto Trading L.L.C. P 0
47755 Bestway 11"X7.5 Air Step Air Pump, 62004 Pronto Trading L.L.C. P 0
47756 Bestway 11"X8.5" Air Step Pro-Air Pump, 62005 Pronto Trading L.L.C. P 0
47757 Bestway 5"/13Cm Air Step - Air Pump, 62007 Pronto Trading L.L.C. P 0
47758 Bestway 11" Mini Air Hammer-Inflation Pump, 62008 Pronto Trading L.L.C. P 0
47760 Bestway 9" X 6" Air Step - Air Pump, 62023 Pronto Trading L.L.C. P 0
47761 Bestway 19/48Cm Air Hammer Inflation Pump, 62030 Pronto Trading L.L.C. P 0
47762 Bestway Sidewinder D Cell Air Pump, 62038 Pronto Trading L.L.C. P 0
47763 Bestway Sidewinder Ac Air Pump, 62056 Pronto Trading L.L.C. P 0
47764 Bestway 12V Sidewinder Ac/Dc Airpump, 62076 Pronto Trading L.L.C. P 0
47765 Bestway 14.5" Air Hammer-Inflation Pump, 62086 Pronto Trading L.L.C. P 0
47766 Bestway 2.5"x2.5" Underwater Adhesive Repair Kit, 62091 Pronto Trading L.L.C. P 0
47767 Bestway Powergrip Electric Air Pump , 62098 Pronto Trading L.L.C. P 0
47768 Bestway Aire Travel Portable Usb Pump, 62101 Pronto Trading L.L.C. P 0
47769 Bestway Cooler Z 27.5Cm X 20.5Cm Splash Guard, 62103 Pronto Trading L.L.C. P 0
47770 Bestway 67445 Inflatable Travel Pillow, Light Blue Pronto Trading L.L.C. P 0
47771 Bestway 1.12Mx90Cm Kids Ball Pit & Play Land, 68080 Pronto Trading L.L.C. P 0
47772 Bestway Fruit Kiddie Lounge Chair 44.5X41X21.5Cm, 75066 Pronto Trading L.L.C. P 0
47773 Bestway Princess 9"X 16" Armband, 91041 Pronto Trading L.L.C. P 0
47774 Bestway - 5.49M Single Slide, 91208 Pronto Trading L.L.C. P 0
45784 Bestway - Pavillo 20L Solar-Pro Shower Pronto Trading L.L.C. P 0
45785 Bestway Aslepa Airbed Single 73"X30"X8.5", 67434 Pronto Trading L.L.C. P 0
45786 Bestway 75"X54"X8.5" Aslepa Airbed Double, 67436 Pronto Trading L.L.C. P 0
45787 Bestway Pavillo Flex Choice Air Mattress 1.91X70, 67617 Pronto Trading L.L.C. P 0
45788 Bestway 43"X43"X75 Station Port, 68002 Pronto Trading L.L.C. P 0
45789 Bestway 189"X83"X65" Traverse X4 Tent, 68003 Pronto Trading L.L.C. P 0
45790 Bestway 93"X57"X39" Nu Camp X2 Tent, 68004 Pronto Trading L.L.C. P 0
45791 Bestway 83"X94"X39" Nu Camp X4 Tent, 68006 Pronto Trading L.L.C. P 0
45792 Bestway 83"X83"X51" Plateau X3 Tent, 68010 Pronto Trading L.L.C. P 0
45793 Bestway 83"X83"X47" Range X3 Tent, 68012 Pronto Trading L.L.C. P 0
45794 Bestway Bestway 110"X79" Triptrek X 4 Pax Tent, 68013 Pronto Trading L.L.C. P 0
45795 Bestway (39"+83")"X94"X51" Rock Mount X4 Tent, 68014 Pronto Trading L.L.C. P 0
45796 Bestway 120"X 79" Hogan X5 Tent, 68015 Pronto Trading L.L.C. P 0
45797 Bestway 240"X94"X83" Camp Base X6 Tent, 68016 Pronto Trading L.L.C. P 0
45798 Bestway - Blazid 30L Backpack, 68019 Pronto Trading L.L.C. P 0
45799 Bestway - Quari 45L Backpack, 68024 Pronto Trading L.L.C. P 0
45800 Bestway - Quari 45L Backpack, 68025 Pronto Trading L.L.C. P 0
45801 Bestway Dura Trek 45L Backpack, 68028 Pronto Trading L.L.C. P 0
45802 Bestway Dura Trek 45L Backpack, 68029 Pronto Trading L.L.C. P 0
45803 Bestway Dura Trek 65L Backpack, 68030 Pronto Trading L.L.C. P 0
45804 Bestway Dura Trek 65L Backpack, 68031 Pronto Trading L.L.C. P 0
45805 Bestway Pavillo Quellor 25L Cooler Bag, 68037 Pronto Trading L.L.C. P 0
45806 Bestway 57"X81"X39" Monodome X2 Tent, 68040 Pronto Trading L.L.C. P 0
45807 Bestway (39"+83")X94"X51" Montana X4 Tent, 68041 Pronto Trading L.L.C. P 0
45808 Bestway 79"X55"X43" Woodlands X2 Tent, 68042 Pronto Trading L.L.C. P 0
45809 Bestway 79"X51"X35" Beach Tent, 68044 Pronto Trading L.L.C. P 0
45810 Bestway 1.92M X 1.2M X 85Cm Secura Beach Tent, 68045 Pronto Trading L.L.C. P 0
45811 Bestway (28"+79"+28")"X71"X49" Cultiva X3 Tent, 68046 Pronto Trading L.L.C. P 0
45812 Bestway 2.05M X 90Cm Slumber300 Sleeping Bag, 68047 Pronto Trading L.L.C. P 0
45813 Bestway Pavillo 30"X 75" Escapade 200 Sleeping Bag Pronto Trading L.L.C. P 0
45814 Bestway Heat Wrap Sleeping Bag, 91"X31"X22" Pronto Trading L.L.C. P 0
45815 Bestway 65"X26" Kid Camp 150 Sleeping Bag, 68050 Pronto Trading L.L.C. P 0
45816 Bestway 71"X31" Evade 200 Sleeping Bag, 68053 Pronto Trading L.L.C. P 0
45817 Bestway 87"X30"X20"Cmfrt Quest 200 Sleeping Bag, 68054 Pronto Trading L.L.C. P 0
45818 Bestway 75"X33" Hibemator 200 Sleeping Bag, 68055 Pronto Trading L.L.C. P 0
45819 Bestway 79"X26"X1.2" Monodor Camp Mat, 68056 Pronto Trading L.L.C. P 0
45820 Bestway 69"X53" Winder Travel Mat, 68059 Pronto Trading L.L.C. P 0
45821 Bestway 1.9M X 50 Cm X 0.6 Cm Camp Base Sleep Pad, 68061 Pronto Trading L.L.C. P 0
45822 Bestway 75"X25"X16.5"Fold N Rest Camping Bed, 68062 Pronto Trading L.L.C. P 0
45823 Bestway 75"X25"16.5"Fold N Rest Camping Bed, 68065 Pronto Trading L.L.C. P 0
45824 Bestway 82"X30.7"X18.5" Fold N Rest Alu Camp Bed, 68068 Pronto Trading L.L.C. P 0
45825 Bestway 50Cmx50Cmx72Cm Fold N Sit Chair, 68069 Pronto Trading L.L.C. P 0
45826 Bestway 31Cmx31Cmx38Cm Fold N Sit Camping Stool, 68070 Pronto Trading L.L.C. P 0
45827 Bestway 92"X33"X25" Heat Wrap 400 Sleeping Bag, 68072 Pronto Trading L.L.C. P 0
45828 Bestway Pavillo Horizon Edge 30L Backpack, 68076 Pronto Trading L.L.C. P 0
45829 Bestway 4.85 Mx2.70 Mx2.0 M Sierra Ridge Airx4 Tent, 68077 Pronto Trading L.L.C. P 0