question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

parser cache and nestTables issue

See original GitHub issue

Using Knex, the following two queries are built

select `role`.`role_id`, `role`.`name`, `bm_web_player_roles`.`player_id` from `bm_web_player_roles` inner join `bm_web_roles` as `role` on `bm_web_player_roles`.`role_id` = `role`.`role_id` where `bm_web_player_roles`.`player_id` in (X'53458e9db5514e73a7b2d3fac8d41d67', X'1e14467b1013458fa3a1af3fce1eb29f', X'd5918acd7ebb43d8ac42b358f64c5309')
select `serverRole`.`role_id`, `serverRole`.`name`, `bm_web_player_server_roles`.`player_id` from `bm_web_player_server_roles` inner join `bm_web_roles` as `serverRole` on `bm_web_player_server_roles`.`role_id` = `serverRole`.`role_id` where `bm_web_player_server_roles`.`player_id` in (X'53458e9db5514e73a7b2d3fac8d41d67', X'1e14467b1013458fa3a1af3fce1eb29f', X'd5918acd7ebb43d8ac42b358f64c5309')

When executed with mysql2 with the nestTables option set to true, they appear to provide the same key for the joined value despite different aliases.

1st query result:

{
        "role": {
          "role_id": 2,
          "name": "Logged In"
        },
        "bm_web_player_roles": {
          "player_id": {
            "type": "Buffer",
            "data": [
              83,
              69,
              142,
              157,
              181,
              81,
              78,
              115,
              167,
              178,
              211,
              250,
              200,
              212,
              29,
              103
            ]
          }
        }
      },
      {
        "role": {
          "role_id": 2,
          "name": "Logged In"
        },
        "bm_web_player_roles": {
          "player_id": {
            "type": "Buffer",
            "data": [
              213,
              145,
              138,
              205,
              126,
              187,
              67,
              216,
              172,
              66,
              179,
              88,
              246,
              76,
              83,
              9
            ]
          }
        }
      },
      {
        "role": {
          "role_id": 3,
          "name": "Admin"
        },
        "bm_web_player_roles": {
          "player_id": {
            "type": "Buffer",
            "data": [
              30,
              20,
              70,
              123,
              16,
              19,
              69,
              143,
              163,
              161,
              175,
              63,
              206,
              30,
              178,
              159
            ]
          }
        }
      }
    ]

2nd query result:

{
        "role": {
          "role_id": 1,
          "name": "Guest"
        },
        "bm_web_player_roles": {
          "player_id": {
            "type": "Buffer",
            "data": [
              83,
              69,
              142,
              157,
              181,
              81,
              78,
              115,
              167,
              178,
              211,
              250,
              200,
              212,
              29,
              103
            ]
          }
        }
      }
    ]

Note the second query references ‘role’ instead of ‘serverRole’ as defined in the query. If the second query is instead executed first, the key is serverRole for both.

On the surface, this seems to be caused by keyFromFields within parser cache returning the same value for both, and therefore reusing the same parser. Not leveraging the cached parser returns the expected result.

I’m aware this may be an edge case and the queries without context may seem odd. I’m trying to dynamically build queries for a GraphQL server to ensure only requested fields are selected from the database, using the graphql schema object name for the join alias.

Not sure what the best way around this is?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sidorarescommented, Apr 17, 2020

is this what you expect as correct result for the second query?

{
        "serverRole": {
          "role_id": 1,
          "name": "Guest"
        },
        //...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex Parser - consider adding an option to cache ... - GitHub
The user interface to this could be as simple as adding a cacheable: true option the the parser config. Things that need to...
Read more >
What does this parser information mean for my message flow?
When a parser is assigned to do work, it uses its resources to form the current message tree. These resources might be smaller...
Read more >
Manual:Parser cache - MediaWiki
The parser cache is responsible for caching the rendered output of a wiki page. It is the primary caching mechanism for serving page...
Read more >
Parser Cache - Cisco
The Parser Cache feature allows the rapid recognition and translation of configuration lines in a configuration file that differ slightly from previously used ......
Read more >
cache-parser - npm
Node. npm install cache-parser # or yarn add cache-parser. const { parse ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found