SELECT 
  a.category_id 
FROM 
  q_categories as a 
  LEFT JOIN q_categories as b ON b.category_id IN (248) 
WHERE 
  a.id_path LIKE CONCAT(b.id_path, '/%')

Query time 0.00060

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "134.53"
    },
    "nested_loop": [
      {
        "table": {
          "table_name": "b",
          "access_type": "const",
          "possible_keys": [
            "PRIMARY",
            "p_category_id"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "category_id"
          ],
          "key_length": "3",
          "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": "2K"
          },
          "used_columns": [
            "category_id",
            "id_path"
          ]
        }
      },
      {
        "table": {
          "table_name": "a",
          "access_type": "ALL",
          "rows_examined_per_scan": 598,
          "rows_produced_per_join": 66,
          "filtered": "11.11",
          "cost_info": {
            "read_cost": "14.93",
            "eval_cost": "13.29",
            "prefix_cost": "134.53",
            "data_read_per_join": "175K"
          },
          "used_columns": [
            "category_id",
            "id_path"
          ],
          "attached_condition": "(`portal`.`a`.`id_path` like <cache>(concat('248','/%')))"
        }
      }
    ]
  }
}

Result

category_id
249
250
258
259
265
274
279
280
285
303
304
316
324
331
332
345
353
362
396
435
436
490
496
500
506
545
251
257
260
264
266
275
281
284
286
305
317
325
330
333
344
346
354
363
397
492
497
501
507
546
252
261
267
273
276
282
287
288
306
318
326
334
347
352
355
364
398
498
502
508
510
547
253
262
268
277
278
283
289
307
319
327
335
348
356
365
399
499
503
509
511
548
254
263
269
290
302
308
309
320
328
336
349
357
391
489
504
255
270
291
310
315
321
329
337
350
361
392
505
532
256
272
311
322
323
338
351
358
393
271
312
339
359
395
313
340
433
544
314
341
434
566
342
343
459
569
394
598
484
533
535
579
595