Loading ...
Sorry, an error occurred while loading the content.

are FB exceptions expensive?

Expand Messages
  • develop
    Hi Guys, I am running FB 2.0 on FreeBSD. I use FB as data-backend for a multiplayer online game. I am about the increase an int entry which is not allowed to
    Message 1 of 2 , Jul 19, 2011
    • 0 Attachment
      Hi Guys,

      I am running FB 2.0 on FreeBSD. I use FB as data-backend for a
      multiplayer online game.

      I am about the increase an int entry which is not allowed to get greater
      than MAX_VALUE. Which approach would serve better in this case?

      1) trigger to check the old and new value and if the :OLD + :NEW >
      MAX_VALUE then throws an FB exception.

      2) select (first query) the current value, perform add and check if the
      sum is not greater than X. If not then perform an update (second query).

      3) directly perform an update like this:

      "update <table> set <column_name> = <column_name> + value where <pk>=?
      and (<column_name> + value) <= MAX_VALUE" and then check if affected
      rows = 1 or 0.

      in this case I should also provide value for MAX_VALUE.

      Thank you in advance.

      @simeon
    • Roman Rokytskyy
      Hi, ... I guess that options 1) and 3) are pretty equal in terms of network communication, I am not sure whether 1) would produce garbage in the database in
      Message 2 of 2 , Jul 19, 2011
      • 0 Attachment
        Hi,

        > I am about the increase an int entry which is not allowed to get greater
        > than MAX_VALUE. Which approach would serve better in this case?
        >
        > 1) trigger to check the old and new value and if the :OLD + :NEW>
        > MAX_VALUE then throws an FB exception.
        >
        > 2) select (first query) the current value, perform add and check if the
        > sum is not greater than X. If not then perform an update (second query).
        >
        > 3) directly perform an update like this:
        >
        > "update<table> set<column_name> =<column_name> + value where<pk>=?
        > and (<column_name> + value)<= MAX_VALUE" and then check if affected
        > rows = 1 or 0.
        >
        > in this case I should also provide value for MAX_VALUE.

        I guess that options 1) and 3) are pretty equal in terms of network
        communication, I am not sure whether 1) would produce garbage in the
        database in case of exception. If no, then 1) and 3) are pretty
        equivalent, 1) is more flexible, since you can change the constraints
        without changing the application. The option 2) requires two roundtrips,
        which is the slowest of the all options.

        Roman
      Your message has been successfully submitted and would be delivered to recipients shortly.